2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6 * Internet Initiative Japan, Inc (IIJ)
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <netinet/in_systm.h>
35 #include <netinet/in.h>
36 #include <netinet/ip.h>
37 #include <arpa/inet.h>
38 #include <sys/socket.h>
39 #include <net/route.h>
71 #include "throughput.h"
72 #include "slcompress.h"
83 #include "descriptor.h"
103 #include "datalink.h"
109 #define VAR_AUTHKEY 0
112 #define VAR_AUTHNAME 3
113 #define VAR_AUTOLOAD 4
114 #define VAR_WINSIZE 5
120 #define VAR_OPENMODE 11
122 #define VAR_HANGUP 13
123 #define VAR_IDLETIMEOUT 14
124 #define VAR_LQRPERIOD 15
125 #define VAR_LCPRETRY 16
126 #define VAR_CHAPRETRY 17
127 #define VAR_PAPRETRY 18
128 #define VAR_CCPRETRY 19
129 #define VAR_IPCPRETRY 20
133 #define VAR_CALLBACK 24
135 #define VAR_CHOKED 26
136 #define VAR_SENDPIPE 27
137 #define VAR_RECVPIPE 28
138 #define VAR_RADIUS 29
140 #define VAR_PARITY 31
141 #define VAR_CRTSCTS 32
142 #define VAR_URGENT 33
143 #define VAR_LOGOUT 34
144 #define VAR_IFQUEUE 35
146 #define VAR_IPV6CPRETRY 37
147 #define VAR_RAD_ALIVE 38
149 #define VAR_PORT_ID 40
151 /* ``accept|deny|disable|enable'' masks */
152 #define NEG_HISMASK (1)
153 #define NEG_MYMASK (2)
155 /* ``accept|deny|disable|enable'' values */
156 #define NEG_ACFCOMP 40
157 #define NEG_CHAP05 41
158 #define NEG_CHAP80 42
159 #define NEG_CHAP80LM 43
160 #define NEG_DEFLATE 44
163 #define NEG_ENDDISC 47
166 #define NEG_PPPDDEFLATE 50
168 #define NEG_PROTOCOMP 52
169 #define NEG_SHORTSEQ 53
170 #define NEG_VJCOMP 54
172 #define NEG_CHAP81 56
174 const char Version[] = "3.4.2";
176 static int ShowCommand(struct cmdargs const *);
177 static int TerminalCommand(struct cmdargs const *);
178 static int QuitCommand(struct cmdargs const *);
179 static int OpenCommand(struct cmdargs const *);
180 static int CloseCommand(struct cmdargs const *);
181 static int DownCommand(struct cmdargs const *);
182 static int SetCommand(struct cmdargs const *);
183 static int LinkCommand(struct cmdargs const *);
184 static int AddCommand(struct cmdargs const *);
185 static int DeleteCommand(struct cmdargs const *);
186 static int NegotiateCommand(struct cmdargs const *);
187 static int ClearCommand(struct cmdargs const *);
188 static int RunListCommand(struct cmdargs const *);
189 static int IfaceNameCommand(struct cmdargs const *arg);
190 static int IfaceAddCommand(struct cmdargs const *);
191 static int IfaceDeleteCommand(struct cmdargs const *);
192 static int IfaceClearCommand(struct cmdargs const *);
193 static int SetProcTitle(struct cmdargs const *);
195 static int NatEnable(struct cmdargs const *);
196 static int NatOption(struct cmdargs const *);
199 extern struct libalias *la;
202 showcx(struct cmdtab const *cmd)
204 if (cmd->lauth & LOCAL_CX)
206 else if (cmd->lauth & LOCAL_CX_OPT)
213 HelpCommand(struct cmdargs const *arg)
215 struct cmdtab const *cmd;
216 int n, cmax, dmax, cols, cxlen;
220 log_Printf(LogWARN, "help: Cannot help without a prompt\n");
224 if (arg->argc > arg->argn) {
225 for (cmd = arg->cmdtab; cmd->name || cmd->alias; cmd++)
226 if ((cmd->lauth & arg->prompt->auth) &&
227 ((cmd->name && !strcasecmp(cmd->name, arg->argv[arg->argn])) ||
228 (cmd->alias && !strcasecmp(cmd->alias, arg->argv[arg->argn])))) {
229 prompt_Printf(arg->prompt, "%s %s\n", cmd->syntax, showcx(cmd));
236 for (cmd = arg->cmdtab; cmd->func; cmd++)
237 if (cmd->name && (cmd->lauth & arg->prompt->auth)) {
238 if ((n = strlen(cmd->name) + strlen(showcx(cmd))) > cmax)
240 if ((n = strlen(cmd->helpmes)) > dmax)
244 cols = 80 / (dmax + cmax + 3);
246 prompt_Printf(arg->prompt, "(o) = Optional context,"
247 " (c) = Context required\n");
248 for (cmd = arg->cmdtab; cmd->func; cmd++)
249 if (cmd->name && (cmd->lauth & arg->prompt->auth)) {
251 cxlen = cmax - strlen(cmd->name);
253 prompt_Printf(arg->prompt, " ");
254 prompt_Printf(arg->prompt, "%s%-*.*s: %-*.*s",
255 cmd->name, cxlen, cxlen, cx, dmax, dmax, cmd->helpmes);
257 prompt_Printf(arg->prompt, "\n");
260 prompt_Printf(arg->prompt, "\n");
266 IdentCommand(struct cmdargs const *arg)
268 Concatinate(arg->cx->physical->link.lcp.cfg.ident,
269 sizeof arg->cx->physical->link.lcp.cfg.ident,
270 arg->argc - arg->argn, arg->argv + arg->argn);
275 SendIdentification(struct cmdargs const *arg)
277 if (arg->cx->state < DATALINK_LCP) {
278 log_Printf(LogWARN, "sendident: link has not reached LCP\n");
281 return lcp_SendIdentification(&arg->cx->physical->link.lcp) ? 0 : 1;
285 CloneCommand(struct cmdargs const *arg)
287 char namelist[LINE_LEN];
291 if (arg->argc == arg->argn)
294 namelist[sizeof namelist - 1] = '\0';
295 for (f = arg->argn; f < arg->argc; f++) {
296 strncpy(namelist, arg->argv[f], sizeof namelist - 1);
297 for(name = strtok(namelist, ", "); name; name = strtok(NULL,", "))
298 bundle_DatalinkClone(arg->bundle, arg->cx, name);
305 RemoveCommand(struct cmdargs const *arg)
307 if (arg->argc != arg->argn)
310 if (arg->cx->state != DATALINK_CLOSED) {
311 log_Printf(LogWARN, "remove: Cannot delete links that aren't closed\n");
315 bundle_DatalinkRemove(arg->bundle, arg->cx);
320 RenameCommand(struct cmdargs const *arg)
322 if (arg->argc != arg->argn + 1)
325 if (bundle_RenameDatalink(arg->bundle, arg->cx, arg->argv[arg->argn]))
328 log_Printf(LogWARN, "%s -> %s: target name already exists\n",
329 arg->cx->name, arg->argv[arg->argn]);
334 LoadCommand(struct cmdargs const *arg)
339 mode = arg->bundle->phys_type.all;
341 if (arg->argn < arg->argc) {
342 for (n = arg->argn; n < arg->argc; n++)
343 if ((err = system_IsValid(arg->argv[n], arg->prompt, mode)) != NULL) {
344 log_Printf(LogWARN, "%s: %s\n", arg->argv[n], err);
348 for (n = arg->argn; n < arg->argc; n++) {
349 bundle_SetLabel(arg->bundle, arg->argv[arg->argc - 1]);
350 system_Select(arg->bundle, arg->argv[n], CONFFILE, arg->prompt, arg->cx);
352 bundle_SetLabel(arg->bundle, arg->argv[arg->argc - 1]);
353 } else if ((err = system_IsValid("default", arg->prompt, mode)) != NULL) {
354 log_Printf(LogWARN, "default: %s\n", err);
357 bundle_SetLabel(arg->bundle, "default");
358 system_Select(arg->bundle, "default", CONFFILE, arg->prompt, arg->cx);
359 bundle_SetLabel(arg->bundle, "default");
366 LogCommand(struct cmdargs const *arg)
370 if (arg->argn < arg->argc) {
372 int argc = arg->argc - arg->argn;
374 if (argc >= (int)(sizeof argv / sizeof argv[0])) {
375 argc = sizeof argv / sizeof argv[0] - 1;
376 log_Printf(LogWARN, "Truncating log command to %d args\n", argc);
378 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid());
379 Concatinate(buf, sizeof buf, argc, (const char *const *)argv);
380 log_Printf(LogLOG, "%s\n", buf);
381 command_Free(argc, argv);
389 SaveCommand(struct cmdargs const *arg __unused)
391 log_Printf(LogWARN, "save command is not yet implemented.\n");
396 DialCommand(struct cmdargs const *arg)
400 if ((arg->cx && !(arg->cx->physical->type & (PHYS_INTERACTIVE|PHYS_AUTO)))
402 (arg->bundle->phys_type.all & ~(PHYS_INTERACTIVE|PHYS_AUTO)))) {
403 log_Printf(LogWARN, "Manual dial is only available for auto and"
404 " interactive links\n");
408 if (arg->argc > arg->argn && (res = LoadCommand(arg)) != 0)
411 bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL, 1);
416 #define isinword(ch) (isalnum(ch) || (ch) == '_')
419 strstrword(char *big, const char *little)
421 /* Get the first occurrence of the word ``little'' in ``big'' */
426 len = strlen(little);
428 while ((pos = strstr(pos, little)) != NULL)
429 if ((pos != big && isinword(pos[-1])) || isinword(pos[len]))
431 else if (pos != big && pos[-1] == '\\')
432 memmove(pos - 1, pos, strlen(pos) + 1);
440 subst(char *tgt, const char *oldstr, const char *newstr)
442 /* tgt is a malloc()d area... realloc() as necessary */
444 int ltgt, loldstr, lnewstr, pos;
446 if ((word = strstrword(tgt, oldstr)) == NULL)
449 ltgt = strlen(tgt) + 1;
450 loldstr = strlen(oldstr);
451 lnewstr = strlen(newstr);
454 if (loldstr > lnewstr)
455 bcopy(word + loldstr, word + lnewstr, ltgt - pos - loldstr);
456 if (loldstr != lnewstr) {
457 ntgt = realloc(tgt, ltgt += lnewstr - loldstr);
459 break; /* Oh wonderful ! */
463 if (lnewstr > loldstr)
464 bcopy(word + loldstr, word + lnewstr, ltgt - pos - lnewstr);
465 bcopy(newstr, word, lnewstr);
466 } while ((word = strstrword(word, oldstr)));
472 substip(char *tgt, const char *oldstr, struct in_addr ip)
474 return subst(tgt, oldstr, inet_ntoa(ip));
478 substlong(char *tgt, const char *oldstr, long l)
482 snprintf(buf, sizeof buf, "%ld", l);
484 return subst(tgt, oldstr, buf);
488 substull(char *tgt, const char *oldstr, unsigned long long ull)
492 snprintf(buf, sizeof buf, "%llu", ull);
494 return subst(tgt, oldstr, buf);
500 substipv6(char *tgt, const char *oldstr, const struct ncpaddr *ip)
502 return subst(tgt, oldstr, ncpaddr_ntoa(ip));
507 substipv6prefix(char *tgt, const char *oldstr, const uint8_t *ipv6prefix)
509 uint8_t ipv6addr[INET6_ADDRSTRLEN];
510 uint8_t prefix[INET6_ADDRSTRLEN + sizeof("/128") - 1];
513 inet_ntop(AF_INET6, &ipv6prefix[2], ipv6addr, sizeof(ipv6addr));
514 snprintf(prefix, sizeof(prefix), "%s/%d", ipv6addr, ipv6prefix[1]);
517 return subst(tgt, oldstr, prefix);
523 command_Expand(char **nargv, int argc, char const *const *oargv,
524 struct bundle *bundle, int inc0, pid_t pid)
528 unsigned long long oin, oout, pin, pout;
531 arg = 0; /* Start at arg 0 */
533 nargv[0] = strdup(oargv[0]);
537 secs = bundle_Uptime(bundle);
538 snprintf(uptime, sizeof uptime, "%d:%02d:%02d",
539 secs / 3600, (secs / 60) % 60, secs % 60);
540 oin = bundle->ncp.ipcp.throughput.OctetsIn;
541 oout = bundle->ncp.ipcp.throughput.OctetsOut;
542 pin = bundle->ncp.ipcp.throughput.PacketsIn;
543 pout = bundle->ncp.ipcp.throughput.PacketsOut;
545 oin += bundle->ncp.ipv6cp.throughput.OctetsIn;
546 oout += bundle->ncp.ipv6cp.throughput.OctetsOut;
547 pin += bundle->ncp.ipv6cp.throughput.PacketsIn;
548 pout += bundle->ncp.ipv6cp.throughput.PacketsOut;
551 for (; arg < argc; arg++) {
552 nargv[arg] = strdup(oargv[arg]);
553 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
554 nargv[arg] = substip(nargv[arg], "DNS0", bundle->ncp.ipcp.ns.dns[0]);
555 nargv[arg] = substip(nargv[arg], "DNS1", bundle->ncp.ipcp.ns.dns[1]);
556 nargv[arg] = subst(nargv[arg], "ENDDISC",
557 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,
558 bundle->ncp.mp.cfg.enddisc.address,
559 bundle->ncp.mp.cfg.enddisc.len));
560 nargv[arg] = substip(nargv[arg], "HISADDR", bundle->ncp.ipcp.peer_ip);
562 nargv[arg] = substipv6(nargv[arg], "HISADDR6", &bundle->ncp.ipv6cp.hisaddr);
564 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->iface->name);
565 nargv[arg] = substull(nargv[arg], "IPOCTETSIN",
566 bundle->ncp.ipcp.throughput.OctetsIn);
567 nargv[arg] = substull(nargv[arg], "IPOCTETSOUT",
568 bundle->ncp.ipcp.throughput.OctetsOut);
569 nargv[arg] = substull(nargv[arg], "IPPACKETSIN",
570 bundle->ncp.ipcp.throughput.PacketsIn);
571 nargv[arg] = substull(nargv[arg], "IPPACKETSOUT",
572 bundle->ncp.ipcp.throughput.PacketsOut);
574 nargv[arg] = substull(nargv[arg], "IPV6OCTETSIN",
575 bundle->ncp.ipv6cp.throughput.OctetsIn);
576 nargv[arg] = substull(nargv[arg], "IPV6OCTETSOUT",
577 bundle->ncp.ipv6cp.throughput.OctetsOut);
578 nargv[arg] = substull(nargv[arg], "IPV6PACKETSIN",
579 bundle->ncp.ipv6cp.throughput.PacketsIn);
580 nargv[arg] = substull(nargv[arg], "IPV6PACKETSOUT",
581 bundle->ncp.ipv6cp.throughput.PacketsOut);
583 nargv[arg] = subst(nargv[arg], "LABEL", bundle_GetLabel(bundle));
584 nargv[arg] = substip(nargv[arg], "MYADDR", bundle->ncp.ipcp.my_ip);
586 nargv[arg] = substipv6(nargv[arg], "MYADDR6", &bundle->ncp.ipv6cp.myaddr);
588 nargv[arg] = substipv6prefix(nargv[arg], "IPV6PREFIX",
589 bundle->radius.ipv6prefix);
592 nargv[arg] = substull(nargv[arg], "OCTETSIN", oin);
593 nargv[arg] = substull(nargv[arg], "OCTETSOUT", oout);
594 nargv[arg] = substull(nargv[arg], "PACKETSIN", pin);
595 nargv[arg] = substull(nargv[arg], "PACKETSOUT", pout);
596 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC",
597 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class,
598 bundle->ncp.mp.peer.enddisc.address,
599 bundle->ncp.mp.peer.enddisc.len));
600 nargv[arg] = substlong(nargv[arg], "PROCESSID", pid);
602 nargv[arg] = substlong(nargv[arg], "SOCKNAME", server.cfg.port);
604 nargv[arg] = subst(nargv[arg], "SOCKNAME", server.cfg.sockname);
605 nargv[arg] = subst(nargv[arg], "UPTIME", uptime);
606 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
607 nargv[arg] = subst(nargv[arg], "VERSION", Version);
613 command_Free(int argc, char **argv)
623 ShellCommand(struct cmdargs const *arg, int bg)
628 #ifdef SHELL_ONLY_INTERACTIVELY
629 /* we're only allowed to shell when we run ppp interactively */
630 if (arg->prompt && arg->prompt->owner) {
631 log_Printf(LogWARN, "Can't start a shell from a network connection\n");
636 if (arg->argc == arg->argn) {
638 log_Printf(LogWARN, "Can't start an interactive shell from"
641 } else if (arg->prompt->owner) {
642 log_Printf(LogWARN, "Can't start an interactive shell from"
643 " a socket connection\n");
646 log_Printf(LogWARN, "Can only start an interactive shell in"
647 " the foreground mode\n");
653 if ((shpid = fork()) == 0) {
656 if ((shell = getenv("SHELL")) == NULL)
657 shell = _PATH_BSHELL;
662 fd = arg->prompt->fd_out;
663 else if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
664 log_Printf(LogALERT, "Failed to open %s: %s\n",
665 _PATH_DEVNULL, strerror(errno));
668 dup2(fd, STDIN_FILENO);
669 dup2(fd, STDOUT_FILENO);
670 dup2(fd, STDERR_FILENO);
671 for (i = getdtablesize(); i > STDERR_FILENO; i--)
672 fcntl(i, F_SETFD, 1);
675 setuid(ID0realuid());
677 if (arg->argc > arg->argn) {
678 /* substitute pseudo args */
680 int argc = arg->argc - arg->argn;
682 if (argc >= (int)(sizeof argv / sizeof argv[0])) {
683 argc = sizeof argv / sizeof argv[0] - 1;
684 log_Printf(LogWARN, "Truncating shell command to %d args\n", argc);
686 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0, pid);
691 if (daemon(1, 1) == -1) {
692 log_Printf(LogERROR, "%ld: daemon: %s\n", (long)p, strerror(errno));
695 } else if (arg->prompt)
696 printf("ppp: Pausing until %s finishes\n", arg->argv[arg->argn]);
697 execvp(argv[0], argv);
700 printf("ppp: Pausing until %s finishes\n", shell);
701 prompt_TtyOldMode(arg->prompt);
702 execl(shell, shell, (char *)NULL);
705 log_Printf(LogWARN, "exec() of %s failed: %s\n",
706 arg->argc > arg->argn ? arg->argv[arg->argn] : shell,
711 if (shpid == (pid_t)-1)
712 log_Printf(LogERROR, "Fork failed: %s\n", strerror(errno));
715 waitpid(shpid, &status, 0);
718 if (arg->prompt && !arg->prompt->owner)
719 prompt_TtyCommandMode(arg->prompt);
725 BgShellCommand(struct cmdargs const *arg)
727 if (arg->argc == arg->argn)
729 return ShellCommand(arg, 1);
733 FgShellCommand(struct cmdargs const *arg)
735 return ShellCommand(arg, 0);
739 ResolvCommand(struct cmdargs const *arg)
741 if (arg->argc == arg->argn + 1) {
742 if (!strcasecmp(arg->argv[arg->argn], "reload"))
743 ipcp_LoadDNS(&arg->bundle->ncp.ipcp);
744 else if (!strcasecmp(arg->argv[arg->argn], "restore"))
745 ipcp_RestoreDNS(&arg->bundle->ncp.ipcp);
746 else if (!strcasecmp(arg->argv[arg->argn], "rewrite"))
747 ipcp_WriteDNS(&arg->bundle->ncp.ipcp);
748 else if (!strcasecmp(arg->argv[arg->argn], "readonly"))
749 arg->bundle->ncp.ipcp.ns.writable = 0;
750 else if (!strcasecmp(arg->argv[arg->argn], "writable"))
751 arg->bundle->ncp.ipcp.ns.writable = 1;
762 static struct cmdtab const NatCommands[] =
764 {"addr", NULL, nat_RedirectAddr, LOCAL_AUTH,
765 "static address translation", "nat addr [addr_local addr_alias]", NULL},
766 {"deny_incoming", NULL, NatOption, LOCAL_AUTH,
767 "stop incoming connections", "nat deny_incoming yes|no",
768 (const void *) PKT_ALIAS_DENY_INCOMING},
769 {"enable", NULL, NatEnable, LOCAL_AUTH,
770 "enable NAT", "nat enable yes|no", NULL},
771 {"log", NULL, NatOption, LOCAL_AUTH,
772 "log NAT link creation", "nat log yes|no",
773 (const void *) PKT_ALIAS_LOG},
774 {"port", NULL, nat_RedirectPort, LOCAL_AUTH, "port redirection",
775 "nat port proto localaddr:port[-port] aliasport[-aliasport]", NULL},
776 {"proto", NULL, nat_RedirectProto, LOCAL_AUTH, "protocol redirection",
777 "nat proto proto localIP [publicIP [remoteIP]]", NULL},
778 {"proxy", NULL, nat_ProxyRule, LOCAL_AUTH,
779 "proxy control", "nat proxy server host[:port] ...", NULL},
781 {"punch_fw", NULL, nat_PunchFW, LOCAL_AUTH,
782 "firewall control", "nat punch_fw [base count]", NULL},
784 {"skinny_port", NULL, nat_SkinnyPort, LOCAL_AUTH,
785 "TCP port used by Skinny Station protocol", "nat skinny_port [port]", NULL},
786 {"same_ports", NULL, NatOption, LOCAL_AUTH,
787 "try to leave port numbers unchanged", "nat same_ports yes|no",
788 (const void *) PKT_ALIAS_SAME_PORTS},
789 {"target", NULL, nat_SetTarget, LOCAL_AUTH,
790 "Default address for incoming connections", "nat target addr", NULL},
791 {"unregistered_only", NULL, NatOption, LOCAL_AUTH,
792 "translate unregistered (private) IP address space only",
793 "nat unregistered_only yes|no",
794 (const void *) PKT_ALIAS_UNREGISTERED_ONLY},
795 {"use_sockets", NULL, NatOption, LOCAL_AUTH,
796 "allocate host sockets", "nat use_sockets yes|no",
797 (const void *) PKT_ALIAS_USE_SOCKETS},
798 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
799 "Display this message", "nat help|? [command]", NatCommands},
800 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
804 static struct cmdtab const AllowCommands[] = {
805 {"modes", "mode", AllowModes, LOCAL_AUTH,
806 "Only allow certain ppp modes", "allow modes mode...", NULL},
807 {"users", "user", AllowUsers, LOCAL_AUTH,
808 "Only allow ppp access to certain users", "allow users logname...", NULL},
809 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
810 "Display this message", "allow help|? [command]", AllowCommands},
811 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
814 static struct cmdtab const IfaceCommands[] =
816 {"add", NULL, IfaceAddCommand, LOCAL_AUTH,
817 "Add iface address", "iface add addr[/bits| mask] peer", NULL},
818 {NULL, "add!", IfaceAddCommand, LOCAL_AUTH,
819 "Add or change an iface address", "iface add! addr[/bits| mask] peer",
821 {"clear", NULL, IfaceClearCommand, LOCAL_AUTH,
822 "Clear iface address(es)", "iface clear [INET | INET6]", NULL},
823 {"delete", "rm", IfaceDeleteCommand, LOCAL_AUTH,
824 "Delete iface address", "iface delete addr", NULL},
825 {NULL, "rm!", IfaceDeleteCommand, LOCAL_AUTH,
826 "Delete iface address", "iface delete addr", (void *)1},
827 {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH,
828 "Delete iface address", "iface delete addr", (void *)1},
829 {"name", NULL, IfaceNameCommand, LOCAL_AUTH,
830 "Set iface name", "iface name name", NULL},
831 {"description", NULL, iface_Descr, LOCAL_AUTH,
832 "Set iface description", "iface description text", NULL},
833 {"show", NULL, iface_Show, LOCAL_AUTH,
834 "Show iface address(es)", "iface show", NULL},
835 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
836 "Display this message", "nat help|? [command]", IfaceCommands},
837 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
840 static struct cmdtab const Commands[] = {
841 {"accept", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
842 "accept option request", "accept option ..", NULL},
843 {"add", NULL, AddCommand, LOCAL_AUTH,
844 "add route", "add dest mask gateway", NULL},
845 {NULL, "add!", AddCommand, LOCAL_AUTH,
846 "add or change route", "add! dest mask gateway", (void *)1},
847 {"allow", "auth", RunListCommand, LOCAL_AUTH,
848 "Allow ppp access", "allow users|modes ....", AllowCommands},
849 {"bg", "!bg", BgShellCommand, LOCAL_AUTH,
850 "Run a background command", "[!]bg command", NULL},
851 {"clear", NULL, ClearCommand, LOCAL_AUTH | LOCAL_CX_OPT,
852 "Clear throughput statistics",
853 "clear ipcp|ipv6cp|physical [current|overall|peak]...", NULL},
854 {"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
855 "Clone a link", "clone newname...", NULL},
856 {"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
857 "Close an FSM", "close [lcp|ccp]", NULL},
858 {"delete", NULL, DeleteCommand, LOCAL_AUTH,
859 "delete route", "delete dest", NULL},
860 {NULL, "delete!", DeleteCommand, LOCAL_AUTH,
861 "delete a route if it exists", "delete! dest", (void *)1},
862 {"deny", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
863 "Deny option request", "deny option ..", NULL},
864 {"dial", "call", DialCommand, LOCAL_AUTH | LOCAL_CX_OPT,
865 "Dial and login", "dial|call [system ...]", NULL},
866 {"disable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
867 "Disable option", "disable option ..", NULL},
868 {"down", NULL, DownCommand, LOCAL_AUTH | LOCAL_CX_OPT,
869 "Generate a down event", "down [ccp|lcp]", NULL},
870 {"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
871 "Enable option", "enable option ..", NULL},
872 {"ident", NULL, IdentCommand, LOCAL_AUTH | LOCAL_CX,
873 "Set the link identity", "ident text...", NULL},
874 {"iface", "interface", RunListCommand, LOCAL_AUTH,
875 "interface control", "iface option ...", IfaceCommands},
876 {"link", "datalink", LinkCommand, LOCAL_AUTH,
877 "Link specific commands", "link name command ...", NULL},
878 {"load", NULL, LoadCommand, LOCAL_AUTH | LOCAL_CX_OPT,
879 "Load settings", "load [system ...]", NULL},
880 {"log", NULL, LogCommand, LOCAL_AUTH | LOCAL_CX_OPT,
881 "log information", "log word ...", NULL},
883 {"nat", "alias", RunListCommand, LOCAL_AUTH,
884 "NAT control", "nat option yes|no", NatCommands},
886 {"open", NULL, OpenCommand, LOCAL_AUTH | LOCAL_CX_OPT,
887 "Open an FSM", "open! [lcp|ccp|ipcp]", (void *)1},
888 {"passwd", NULL, PasswdCommand, LOCAL_NO_AUTH,
889 "Password for manipulation", "passwd LocalPassword", NULL},
890 {"quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
891 "Quit PPP program", "quit|bye [all]", NULL},
892 {"remove", "rm", RemoveCommand, LOCAL_AUTH | LOCAL_CX,
893 "Remove a link", "remove", NULL},
894 {"rename", "mv", RenameCommand, LOCAL_AUTH | LOCAL_CX,
895 "Rename a link", "rename name", NULL},
896 {"resolv", NULL, ResolvCommand, LOCAL_AUTH,
897 "Manipulate resolv.conf", "resolv readonly|reload|restore|rewrite|writable",
899 {"save", NULL, SaveCommand, LOCAL_AUTH,
900 "Save settings", "save", NULL},
901 {"sendident", NULL, SendIdentification, LOCAL_AUTH | LOCAL_CX,
902 "Transmit the link identity", "sendident", NULL},
903 {"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT,
904 "Set parameters", "set[up] var value", NULL},
905 {"shell", "!", FgShellCommand, LOCAL_AUTH,
906 "Run a subshell", "shell|! [sh command]", NULL},
907 {"show", NULL, ShowCommand, LOCAL_AUTH | LOCAL_CX_OPT,
908 "Show status and stats", "show var", NULL},
909 {"term", NULL, TerminalCommand, LOCAL_AUTH | LOCAL_CX,
910 "Enter terminal mode", "term", NULL},
911 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
912 "Display this message", "help|? [command]", Commands},
913 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
917 ShowEscape(struct cmdargs const *arg)
919 if (arg->cx->physical->async.cfg.EscMap[32]) {
921 const char *sep = "";
923 for (code = 0; code < 32; code++)
924 if (arg->cx->physical->async.cfg.EscMap[code])
925 for (bit = 0; bit < 8; bit++)
926 if (arg->cx->physical->async.cfg.EscMap[code] & (1 << bit)) {
927 prompt_Printf(arg->prompt, "%s0x%02x", sep, (code << 3) + bit);
930 prompt_Printf(arg->prompt, "\n");
936 ShowTimerList(struct cmdargs const *arg)
938 timer_Show(0, arg->prompt);
943 ShowStopped(struct cmdargs const *arg)
945 prompt_Printf(arg->prompt, " Stopped Timer: LCP: ");
946 if (!arg->cx->physical->link.lcp.fsm.StoppedTimer.load)
947 prompt_Printf(arg->prompt, "Disabled");
949 prompt_Printf(arg->prompt, "%ld secs",
950 arg->cx->physical->link.lcp.fsm.StoppedTimer.load / SECTICKS);
952 prompt_Printf(arg->prompt, ", CCP: ");
953 if (!arg->cx->physical->link.ccp.fsm.StoppedTimer.load)
954 prompt_Printf(arg->prompt, "Disabled");
956 prompt_Printf(arg->prompt, "%ld secs",
957 arg->cx->physical->link.ccp.fsm.StoppedTimer.load / SECTICKS);
959 prompt_Printf(arg->prompt, "\n");
965 ShowVersion(struct cmdargs const *arg)
967 prompt_Printf(arg->prompt, "PPP Version %s\n", Version);
972 ShowProtocolStats(struct cmdargs const *arg)
974 struct link *l = command_ChooseLink(arg);
976 prompt_Printf(arg->prompt, "%s:\n", l->name);
977 link_ReportProtocolStatus(l, arg->prompt);
981 static struct cmdtab const ShowCommands[] = {
982 {"bundle", NULL, bundle_ShowStatus, LOCAL_AUTH,
983 "bundle details", "show bundle", NULL},
984 {"ccp", NULL, ccp_ReportStatus, LOCAL_AUTH | LOCAL_CX_OPT,
985 "CCP status", "show cpp", NULL},
986 {"compress", NULL, sl_Show, LOCAL_AUTH,
987 "VJ compression stats", "show compress", NULL},
988 {"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
989 "escape characters", "show escape", NULL},
990 {"filter", NULL, filter_Show, LOCAL_AUTH,
991 "packet filters", "show filter [in|out|dial|alive]", NULL},
992 {"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
993 "HDLC errors", "show hdlc", NULL},
994 {"iface", "interface", iface_Show, LOCAL_AUTH,
995 "Interface status", "show iface", NULL},
996 {"ipcp", NULL, ipcp_Show, LOCAL_AUTH,
997 "IPCP status", "show ipcp", NULL},
999 {"ipv6cp", NULL, ipv6cp_Show, LOCAL_AUTH,
1000 "IPV6CP status", "show ipv6cp", NULL},
1002 {"layers", NULL, link_ShowLayers, LOCAL_AUTH | LOCAL_CX_OPT,
1003 "Protocol layers", "show layers", NULL},
1004 {"lcp", NULL, lcp_ReportStatus, LOCAL_AUTH | LOCAL_CX,
1005 "LCP status", "show lcp", NULL},
1006 {"link", "datalink", datalink_Show, LOCAL_AUTH | LOCAL_CX,
1007 "(high-level) link info", "show link", NULL},
1008 {"links", NULL, bundle_ShowLinks, LOCAL_AUTH,
1009 "available link names", "show links", NULL},
1010 {"log", NULL, log_ShowLevel, LOCAL_AUTH,
1011 "log levels", "show log", NULL},
1012 {"mem", NULL, mbuf_Show, LOCAL_AUTH,
1013 "mbuf allocations", "show mem", NULL},
1014 {"ncp", NULL, ncp_Show, LOCAL_AUTH,
1015 "NCP status", "show ncp", NULL},
1016 {"physical", NULL, physical_ShowStatus, LOCAL_AUTH | LOCAL_CX,
1017 "(low-level) link info", "show physical", NULL},
1018 {"mp", "multilink", mp_ShowStatus, LOCAL_AUTH,
1019 "multilink setup", "show mp", NULL},
1020 {"proto", NULL, ShowProtocolStats, LOCAL_AUTH | LOCAL_CX_OPT,
1021 "protocol summary", "show proto", NULL},
1022 {"route", NULL, route_Show, LOCAL_AUTH,
1023 "routing table", "show route", NULL},
1024 {"stopped", NULL, ShowStopped, LOCAL_AUTH | LOCAL_CX,
1025 "STOPPED timeout", "show stopped", NULL},
1026 {"timers", NULL, ShowTimerList, LOCAL_AUTH,
1027 "alarm timers", "show timers", NULL},
1028 {"version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
1029 "version string", "show version", NULL},
1030 {"who", NULL, log_ShowWho, LOCAL_AUTH,
1031 "client list", "show who", NULL},
1032 {"help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH,
1033 "Display this message", "show help|? [command]", ShowCommands},
1034 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
1037 static struct cmdtab const *
1038 FindCommand(struct cmdtab const *cmds, const char *str, int *pmatch)
1042 struct cmdtab const *found;
1047 while (cmds->func) {
1048 if (cmds->name && strncasecmp(str, cmds->name, len) == 0) {
1049 if (cmds->name[len] == '\0') {
1055 } else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) {
1056 if (cmds->alias[len] == '\0') {
1070 mkPrefix(int argc, char const *const *argv, char *tgt, int sz)
1075 for (f = 0; f < argc && tlen < sz - 2; f++) {
1078 len = strlen(argv[f]);
1079 if (len > sz - tlen - 1)
1080 len = sz - tlen - 1;
1081 strncpy(tgt+tlen, argv[f], len);
1089 FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc, int argn,
1090 char const *const *argv, struct prompt *prompt, struct datalink *cx)
1092 struct cmdtab const *cmd;
1098 cmd = FindCommand(cmds, argv[argn], &nmatch);
1100 log_Printf(LogWARN, "%s: Ambiguous command\n",
1101 mkPrefix(argn+1, argv, prefix, sizeof prefix));
1102 else if (cmd && (!prompt || (cmd->lauth & prompt->auth))) {
1103 if ((cmd->lauth & LOCAL_CX) && !cx)
1104 /* We've got no context, but we require it */
1105 cx = bundle2datalink(bundle, NULL);
1107 if ((cmd->lauth & LOCAL_CX) && !cx)
1108 log_Printf(LogWARN, "%s: No context (use the `link' command)\n",
1109 mkPrefix(argn+1, argv, prefix, sizeof prefix));
1111 if (cx && !(cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
1112 log_Printf(LogWARN, "%s: Redundant context (%s) ignored\n",
1113 mkPrefix(argn+1, argv, prefix, sizeof prefix), cx->name);
1121 arg.bundle = bundle;
1123 arg.prompt = prompt;
1124 val = (*cmd->func) (&arg);
1127 log_Printf(LogWARN, "%s: Invalid command\n",
1128 mkPrefix(argn+1, argv, prefix, sizeof prefix));
1131 log_Printf(LogWARN, "usage: %s\n", cmd->syntax);
1133 log_Printf(LogWARN, "%s: Failed %d\n",
1134 mkPrefix(argn+1, argv, prefix, sizeof prefix), val);
1140 command_Expand_Interpret(char *buff, int nb, char *argv[MAXARGS], int offset)
1142 char buff2[LINE_LEN-offset];
1144 InterpretArg(buff, buff2);
1145 strncpy(buff, buff2, LINE_LEN - offset - 1);
1146 buff[LINE_LEN - offset - 1] = '\0';
1148 return command_Interpret(buff, nb, argv);
1152 command_Interpret(char *buff, int nb, char *argv[MAXARGS])
1157 cp = buff + strcspn(buff, "\r\n");
1160 return MakeArgs(buff, argv, MAXARGS, PARSE_REDUCE);
1166 arghidden(char const *const *argv, int n)
1168 /* Is arg n of the given command to be hidden from the log ? */
1170 /* set authkey xxxxx */
1172 if (n == 2 && !strncasecmp(argv[0], "se", 2) &&
1173 (!strncasecmp(argv[1], "authk", 5) || !strncasecmp(argv[1], "ke", 2)))
1177 if (n == 1 && !strncasecmp(argv[0], "p", 1))
1180 /* set server port xxxxx .... */
1181 if (n == 3 && !strncasecmp(argv[0], "se", 2) &&
1182 !strncasecmp(argv[1], "se", 2))
1189 command_Run(struct bundle *bundle, int argc, char const *const *argv,
1190 struct prompt *prompt, const char *label, struct datalink *cx)
1193 if (log_IsKept(LogCOMMAND)) {
1199 strncpy(buf, label, sizeof buf - 3);
1200 buf[sizeof buf - 3] = '\0';
1207 buf[sizeof buf - 1] = '\0'; /* In case we run out of room in buf */
1209 for (f = 0; f < argc; f++) {
1210 if (n < sizeof buf - 1 && f)
1212 if (arghidden(argv, f))
1213 strncpy(buf+n, "********", sizeof buf - n - 1);
1215 strncpy(buf+n, argv[f], sizeof buf - n - 1);
1218 log_Printf(LogCOMMAND, "%s\n", buf);
1220 FindExec(bundle, Commands, argc, 0, argv, prompt, cx);
1225 command_Decode(struct bundle *bundle, char *buff, int nb, struct prompt *prompt,
1229 char *argv[MAXARGS];
1231 if ((argc = command_Expand_Interpret(buff, nb, argv, 0)) < 0)
1234 command_Run(bundle, argc, (char const *const *)argv, prompt, label, NULL);
1239 ShowCommand(struct cmdargs const *arg)
1242 log_Printf(LogWARN, "show: Cannot show without a prompt\n");
1243 else if (arg->argc > arg->argn)
1244 FindExec(arg->bundle, ShowCommands, arg->argc, arg->argn, arg->argv,
1245 arg->prompt, arg->cx);
1247 prompt_Printf(arg->prompt, "Use ``show ?'' to get a list.\n");
1253 TerminalCommand(struct cmdargs const *arg)
1256 log_Printf(LogWARN, "term: Need a prompt\n");
1260 if (arg->cx->physical->link.lcp.fsm.state > ST_CLOSED) {
1261 prompt_Printf(arg->prompt, "LCP state is [%s]\n",
1262 State2Nam(arg->cx->physical->link.lcp.fsm.state));
1266 datalink_Up(arg->cx, 0, 0);
1267 prompt_TtyTermMode(arg->prompt, arg->cx);
1272 QuitCommand(struct cmdargs const *arg)
1274 if (!arg->prompt || prompt_IsController(arg->prompt) ||
1275 (arg->argc > arg->argn && !strcasecmp(arg->argv[arg->argn], "all") &&
1276 (arg->prompt->auth & LOCAL_AUTH)))
1279 prompt_Destroy(arg->prompt, 1);
1285 OpenCommand(struct cmdargs const *arg)
1287 if (arg->argc == arg->argn)
1288 bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL, 1);
1289 else if (arg->argc == arg->argn + 1) {
1290 if (!strcasecmp(arg->argv[arg->argn], "lcp")) {
1291 struct datalink *cx = arg->cx ?
1292 arg->cx : bundle2datalink(arg->bundle, NULL);
1294 if (cx->physical->link.lcp.fsm.state == ST_OPENED)
1295 fsm_Reopen(&cx->physical->link.lcp.fsm);
1297 bundle_Open(arg->bundle, cx->name, PHYS_ALL, 1);
1299 log_Printf(LogWARN, "open lcp: You must specify a link\n");
1300 } else if (!strcasecmp(arg->argv[arg->argn], "ccp")) {
1303 fp = &command_ChooseLink(arg)->ccp.fsm;
1304 if (fp->link->lcp.fsm.state != ST_OPENED)
1305 log_Printf(LogWARN, "open: LCP must be open before opening CCP\n");
1306 else if (fp->state == ST_OPENED)
1309 fp->open_mode = 0; /* Not passive any more */
1310 if (fp->state == ST_STOPPED) {
1318 } else if (!strcasecmp(arg->argv[arg->argn], "ipcp")) {
1320 log_Printf(LogWARN, "open ipcp: You need not specify a link\n");
1321 if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED)
1322 fsm_Reopen(&arg->bundle->ncp.ipcp.fsm);
1324 bundle_Open(arg->bundle, NULL, PHYS_ALL, 1);
1334 CloseCommand(struct cmdargs const *arg)
1336 if (arg->argc == arg->argn)
1337 bundle_Close(arg->bundle, arg->cx ? arg->cx->name : NULL, CLOSE_STAYDOWN);
1338 else if (arg->argc == arg->argn + 1) {
1339 if (!strcasecmp(arg->argv[arg->argn], "lcp"))
1340 bundle_Close(arg->bundle, arg->cx ? arg->cx->name : NULL, CLOSE_LCP);
1341 else if (!strcasecmp(arg->argv[arg->argn], "ccp") ||
1342 !strcasecmp(arg->argv[arg->argn], "ccp!")) {
1345 fp = &command_ChooseLink(arg)->ccp.fsm;
1346 if (fp->state == ST_OPENED) {
1348 if (arg->argv[arg->argn][3] == '!')
1349 fp->open_mode = 0; /* Stay ST_CLOSED */
1351 fp->open_mode = OPEN_PASSIVE; /* Wait for the peer to start */
1362 DownCommand(struct cmdargs const *arg)
1364 if (arg->argc == arg->argn) {
1366 datalink_Down(arg->cx, CLOSE_STAYDOWN);
1368 bundle_Down(arg->bundle, CLOSE_STAYDOWN);
1369 } else if (arg->argc == arg->argn + 1) {
1370 if (!strcasecmp(arg->argv[arg->argn], "lcp")) {
1372 datalink_Down(arg->cx, CLOSE_LCP);
1374 bundle_Down(arg->bundle, CLOSE_LCP);
1375 } else if (!strcasecmp(arg->argv[arg->argn], "ccp")) {
1376 struct fsm *fp = arg->cx ? &arg->cx->physical->link.ccp.fsm :
1377 &arg->bundle->ncp.mp.link.ccp.fsm;
1388 SetModemSpeed(struct cmdargs const *arg)
1393 if (arg->argc > arg->argn && *arg->argv[arg->argn]) {
1394 if (arg->argc > arg->argn+1) {
1395 log_Printf(LogWARN, "SetModemSpeed: Too many arguments\n");
1398 if (strcasecmp(arg->argv[arg->argn], "sync") == 0) {
1399 physical_SetSync(arg->cx->physical);
1403 speed = strtol(arg->argv[arg->argn], &end, 10);
1404 if (*end || speed < 0) {
1405 log_Printf(LogWARN, "SetModemSpeed: Bad argument \"%s\"",
1406 arg->argv[arg->argn]);
1409 if (physical_SetSpeed(arg->cx->physical, speed))
1411 log_Printf(LogWARN, "%s: Invalid speed\n", arg->argv[arg->argn]);
1413 log_Printf(LogWARN, "SetModemSpeed: No speed specified\n");
1419 SetStoppedTimeout(struct cmdargs const *arg)
1421 struct link *l = &arg->cx->physical->link;
1423 l->lcp.fsm.StoppedTimer.load = 0;
1424 l->ccp.fsm.StoppedTimer.load = 0;
1425 if (arg->argc <= arg->argn+2) {
1426 if (arg->argc > arg->argn) {
1427 l->lcp.fsm.StoppedTimer.load = atoi(arg->argv[arg->argn]) * SECTICKS;
1428 if (arg->argc > arg->argn+1)
1429 l->ccp.fsm.StoppedTimer.load = atoi(arg->argv[arg->argn+1]) * SECTICKS;
1437 SetServer(struct cmdargs const *arg)
1441 if (arg->argc > arg->argn && arg->argc < arg->argn+4) {
1442 const char *port, *passwd, *mask;
1446 port = arg->argv[arg->argn];
1447 if (arg->argc == arg->argn + 2) {
1448 passwd = arg->argv[arg->argn+1];
1450 } else if (arg->argc == arg->argn + 3) {
1451 passwd = arg->argv[arg->argn+1];
1452 mask = arg->argv[arg->argn+2];
1453 mlen = strlen(mask);
1454 if (mlen == 0 || mlen > 4 || strspn(mask, "01234567") != mlen ||
1455 (mlen == 4 && *mask != '0')) {
1456 log_Printf(LogWARN, "%s %s: %s: Invalid mask\n",
1457 arg->argv[arg->argn - 2], arg->argv[arg->argn - 1], mask);
1460 } else if (arg->argc != arg->argn + 1)
1462 else if (strcasecmp(port, "none") == 0) {
1463 if (server_Clear(arg->bundle))
1464 log_Printf(LogPHASE, "Disabled server socket\n");
1466 } else if (strcasecmp(port, "open") == 0) {
1467 switch (server_Reopen(arg->bundle)) {
1471 log_Printf(LogWARN, "Failed to reopen server port\n");
1474 log_Printf(LogWARN, "Cannot reopen unset server socket\n");
1480 } else if (strcasecmp(port, "closed") == 0) {
1481 if (server_Close(arg->bundle))
1482 log_Printf(LogPHASE, "Closed server socket\n");
1484 log_Printf(LogWARN, "Server socket not open\n");
1490 strncpy(server.cfg.passwd, passwd, sizeof server.cfg.passwd - 1);
1491 server.cfg.passwd[sizeof server.cfg.passwd - 1] = '\0';
1495 char *ptr, name[LINE_LEN + 12];
1499 else for (imask = mlen = 0; mask[mlen]; mlen++)
1500 imask = (imask * 8) + mask[mlen] - '0';
1502 ptr = strstr(port, "%d");
1504 snprintf(name, sizeof name, "%.*s%d%s",
1505 (int)(ptr - port), port, arg->bundle->unit, ptr + 2);
1508 res = server_LocalOpen(arg->bundle, port, imask);
1519 if (strspn(port, "0123456789") != strlen(port)) {
1522 if ((s = getservbyname(port, "tcp")) == NULL) {
1524 log_Printf(LogWARN, "%s: Invalid port or service\n", port);
1526 iport = ntohs(s->s_port);
1532 iport += arg->bundle->unit;
1533 res = server_TcpOpen(arg->bundle, iport);
1543 SetEscape(struct cmdargs const *arg)
1546 int argc = arg->argc - arg->argn;
1547 char const *const *argv = arg->argv + arg->argn;
1549 for (code = 0; code < 33; code++)
1550 arg->cx->physical->async.cfg.EscMap[code] = 0;
1552 while (argc-- > 0) {
1553 sscanf(*argv++, "%x", &code);
1555 arg->cx->physical->async.cfg.EscMap[code >> 3] |= (1 << (code & 7));
1556 arg->cx->physical->async.cfg.EscMap[32] = 1;
1562 SetInterfaceAddr(struct cmdargs const *arg)
1564 struct ncp *ncp = &arg->bundle->ncp;
1565 struct ncpaddr ncpaddr;
1566 const char *hisaddr;
1568 if (arg->argc > arg->argn + 4)
1572 memset(&ncp->ipcp.cfg.my_range, '\0', sizeof ncp->ipcp.cfg.my_range);
1573 memset(&ncp->ipcp.cfg.peer_range, '\0', sizeof ncp->ipcp.cfg.peer_range);
1574 ncp->ipcp.cfg.HaveTriggerAddress = 0;
1575 ncp->ipcp.cfg.netmask.s_addr = INADDR_ANY;
1576 iplist_reset(&ncp->ipcp.cfg.peer_list);
1578 if (arg->argc > arg->argn) {
1579 if (!ncprange_aton(&ncp->ipcp.cfg.my_range, ncp, arg->argv[arg->argn]))
1581 if (arg->argc > arg->argn+1) {
1582 hisaddr = arg->argv[arg->argn+1];
1583 if (arg->argc > arg->argn+2) {
1584 ncp->ipcp.ifmask = ncp->ipcp.cfg.netmask =
1585 GetIpAddr(arg->argv[arg->argn+2]);
1586 if (arg->argc > arg->argn+3) {
1587 ncp->ipcp.cfg.TriggerAddress = GetIpAddr(arg->argv[arg->argn+3]);
1588 ncp->ipcp.cfg.HaveTriggerAddress = 1;
1594 /* 0.0.0.0 means any address (0 bits) */
1595 ncprange_getaddr(&ncp->ipcp.cfg.my_range, &ncpaddr);
1596 ncpaddr_getip4(&ncpaddr, &ncp->ipcp.my_ip);
1597 if (ncp->ipcp.my_ip.s_addr == INADDR_ANY)
1598 ncprange_setwidth(&ncp->ipcp.cfg.my_range, 0);
1599 bundle_AdjustFilters(arg->bundle, &ncpaddr, NULL);
1601 if (hisaddr && !ipcp_UseHisaddr(arg->bundle, hisaddr,
1602 arg->bundle->phys_type.all & PHYS_AUTO))
1609 SetRetry(int argc, char const *const *argv, u_int *timeout, u_int *maxreq,
1610 u_int *maxtrm, int def)
1613 *timeout = DEF_FSMRETRY;
1618 long l = atol(argv[0]);
1620 if (l < MIN_FSMRETRY) {
1621 log_Printf(LogWARN, "%ld: Invalid FSM retry period - min %d\n",
1630 log_Printf(LogWARN, "%ld: Invalid FSM REQ tries - changed to 1\n", l);
1635 if (argc > 2 && maxtrm != NULL) {
1638 log_Printf(LogWARN, "%ld: Invalid FSM TRM tries - changed to 1\n", l);
1650 SetVariable(struct cmdargs const *arg)
1652 long long_val, param = (long)arg->cmd->args;
1653 int mode, dummyint, f, first, res;
1656 struct datalink *cx = arg->cx; /* LOCAL_CX uses this */
1657 struct link *l = command_ChooseLink(arg); /* LOCAL_CX_OPT uses this */
1658 struct in_addr *ipaddr;
1659 struct ncpaddr ncpaddr[2];
1661 if (arg->argc > arg->argn)
1662 argp = arg->argv[arg->argn];
1668 if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
1669 log_Printf(LogWARN, "set %s: No context (use the `link' command)\n",
1672 } else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
1673 log_Printf(LogWARN, "set %s: Redundant context (%s) ignored\n",
1674 arg->cmd->name, cx->name);
1680 strncpy(arg->bundle->cfg.auth.key, argp,
1681 sizeof arg->bundle->cfg.auth.key - 1);
1682 arg->bundle->cfg.auth.key[sizeof arg->bundle->cfg.auth.key - 1] = '\0';
1686 switch (bundle_Phase(arg->bundle)) {
1688 log_Printf(LogWARN, "Altering authname while at phase %s\n",
1689 bundle_PhaseName(arg->bundle));
1692 case PHASE_ESTABLISH:
1693 strncpy(arg->bundle->cfg.auth.name, argp,
1694 sizeof arg->bundle->cfg.auth.name - 1);
1695 arg->bundle->cfg.auth.name[sizeof arg->bundle->cfg.auth.name-1] = '\0';
1701 if (arg->argc == arg->argn + 3) {
1705 v1 = strtol(arg->argv[arg->argn], &end, 0);
1706 if (v1 < 0 || *end) {
1707 log_Printf(LogWARN, "autoload: %s: Invalid min percentage\n",
1708 arg->argv[arg->argn]);
1713 v2 = strtol(arg->argv[arg->argn + 1], &end, 0);
1714 if (v2 < 0 || *end) {
1715 log_Printf(LogWARN, "autoload: %s: Invalid max percentage\n",
1716 arg->argv[arg->argn + 1]);
1726 v3 = strtol(arg->argv[arg->argn + 2], &end, 0);
1727 if (v3 <= 0 || *end) {
1728 log_Printf(LogWARN, "autoload: %s: Invalid throughput period\n",
1729 arg->argv[arg->argn + 2]);
1734 arg->bundle->ncp.mp.cfg.autoload.min = v1;
1735 arg->bundle->ncp.mp.cfg.autoload.max = v2;
1736 arg->bundle->ncp.mp.cfg.autoload.period = v3;
1737 mp_RestartAutoloadTimer(&arg->bundle->ncp.mp);
1739 log_Printf(LogWARN, "Set autoload requires three arguments\n");
1745 strncpy(cx->cfg.script.dial, argp, sizeof cx->cfg.script.dial - 1);
1746 cx->cfg.script.dial[sizeof cx->cfg.script.dial - 1] = '\0';
1750 strncpy(cx->cfg.script.login, argp, sizeof cx->cfg.script.login - 1);
1751 cx->cfg.script.login[sizeof cx->cfg.script.login - 1] = '\0';
1755 if (arg->argc > arg->argn) {
1756 l->ccp.cfg.deflate.out.winsize = atoi(arg->argv[arg->argn]);
1757 if (l->ccp.cfg.deflate.out.winsize < 8 ||
1758 l->ccp.cfg.deflate.out.winsize > 15) {
1759 log_Printf(LogWARN, "%d: Invalid outgoing window size\n",
1760 l->ccp.cfg.deflate.out.winsize);
1761 l->ccp.cfg.deflate.out.winsize = 15;
1763 if (arg->argc > arg->argn+1) {
1764 l->ccp.cfg.deflate.in.winsize = atoi(arg->argv[arg->argn+1]);
1765 if (l->ccp.cfg.deflate.in.winsize < 8 ||
1766 l->ccp.cfg.deflate.in.winsize > 15) {
1767 log_Printf(LogWARN, "%d: Invalid incoming window size\n",
1768 l->ccp.cfg.deflate.in.winsize);
1769 l->ccp.cfg.deflate.in.winsize = 15;
1772 l->ccp.cfg.deflate.in.winsize = 0;
1774 log_Printf(LogWARN, "No window size specified\n");
1781 if (arg->argc > arg->argn + 2) {
1786 if (arg->argc == arg->argn) {
1787 l->ccp.cfg.mppe.keybits = 0;
1788 l->ccp.cfg.mppe.state = MPPE_ANYSTATE;
1789 l->ccp.cfg.mppe.required = 0;
1793 if (!strcmp(argp, "*"))
1796 long_val = atol(argp);
1797 if (long_val != 40 && long_val != 56 && long_val != 128) {
1798 log_Printf(LogWARN, "%s: Invalid bits value\n", argp);
1804 if (arg->argc == arg->argn + 2) {
1805 if (!strcmp(arg->argv[arg->argn + 1], "*"))
1806 l->ccp.cfg.mppe.state = MPPE_ANYSTATE;
1807 else if (!strcasecmp(arg->argv[arg->argn + 1], "stateless"))
1808 l->ccp.cfg.mppe.state = MPPE_STATELESS;
1809 else if (!strcasecmp(arg->argv[arg->argn + 1], "stateful"))
1810 l->ccp.cfg.mppe.state = MPPE_STATEFUL;
1812 log_Printf(LogWARN, "%s: Invalid state value\n",
1813 arg->argv[arg->argn + 1]);
1818 l->ccp.cfg.mppe.state = MPPE_ANYSTATE;
1819 l->ccp.cfg.mppe.keybits = long_val;
1820 l->ccp.cfg.mppe.required = 1;
1825 physical_SetDeviceList(cx->physical, arg->argc - arg->argn,
1826 arg->argv + arg->argn);
1830 if (arg->argc > arg->argn) {
1832 sscanf(argp, "%lx", &ulong_val);
1833 cx->physical->link.lcp.cfg.accmap = (u_int32_t)ulong_val;
1835 log_Printf(LogWARN, "No accmap specified\n");
1841 mode = Nam2mode(argp);
1842 if (mode == PHYS_NONE || mode == PHYS_ALL) {
1843 log_Printf(LogWARN, "%s: Invalid mode\n", argp);
1847 bundle_SetMode(arg->bundle, cx, mode);
1851 switch (bundle_Phase(arg->bundle)) {
1854 case PHASE_ESTABLISH:
1855 /* Make sure none of our links are DATALINK_LCP or greater */
1856 if (bundle_HighestState(arg->bundle) >= DATALINK_LCP) {
1857 log_Printf(LogWARN, "mrru: Only changeable before LCP negotiations\n");
1863 log_Printf(LogWARN, "mrru: Only changeable at phase DEAD/ESTABLISH\n");
1869 long_val = atol(argp);
1870 if (long_val && long_val < MIN_MRU) {
1871 log_Printf(LogWARN, "MRRU %ld: too small - min %d\n", long_val, MIN_MRU);
1874 } else if (long_val > MAX_MRU) {
1875 log_Printf(LogWARN, "MRRU %ld: too big - max %d\n", long_val, MAX_MRU);
1879 arg->bundle->ncp.mp.cfg.mrru = long_val;
1883 long_val = 0; /* silence gcc */
1884 change = NULL; /* silence gcc */
1885 switch(arg->argc - arg->argn) {
1887 if (argp[strspn(argp, "0123456789")] != '\0') {
1893 long_val = atol(argp);
1894 change = &l->lcp.cfg.mru;
1895 if (long_val > l->lcp.cfg.max_mru) {
1896 log_Printf(LogWARN, "MRU %ld: too large - max set to %d\n", long_val,
1897 l->lcp.cfg.max_mru);
1903 if (strcasecmp(argp, "max") && strcasecmp(argp, "maximum")) {
1907 long_val = atol(arg->argv[arg->argn + 1]);
1908 change = &l->lcp.cfg.max_mru;
1909 if (long_val > MAX_MRU) {
1910 log_Printf(LogWARN, "MRU %ld: too large - maximum is %d\n", long_val,
1925 else if (long_val < MIN_MRU) {
1926 log_Printf(LogWARN, "MRU %ld: too small - min %d\n", long_val, MIN_MRU);
1929 } else if (long_val > MAX_MRU) {
1930 log_Printf(LogWARN, "MRU %ld: too big - max %d\n", long_val, MAX_MRU);
1935 if (l->lcp.cfg.mru > *change)
1936 l->lcp.cfg.mru = *change;
1940 long_val = 0; /* silence gcc */
1941 change = NULL; /* silence gcc */
1942 switch(arg->argc - arg->argn) {
1944 if (argp[strspn(argp, "0123456789")] != '\0') {
1950 long_val = atol(argp);
1951 change = &l->lcp.cfg.mtu;
1952 if (long_val > l->lcp.cfg.max_mtu) {
1953 log_Printf(LogWARN, "MTU %ld: too large - max set to %d\n", long_val,
1954 l->lcp.cfg.max_mtu);
1960 if (strcasecmp(argp, "max") && strcasecmp(argp, "maximum")) {
1964 long_val = atol(arg->argv[arg->argn + 1]);
1965 change = &l->lcp.cfg.max_mtu;
1966 if (long_val > MAX_MTU) {
1967 log_Printf(LogWARN, "MTU %ld: too large - maximum is %d\n", long_val,
1981 if (long_val && long_val < MIN_MTU) {
1982 log_Printf(LogWARN, "MTU %ld: too small - min %d\n", long_val, MIN_MTU);
1985 } else if (long_val > MAX_MTU) {
1986 log_Printf(LogWARN, "MTU %ld: too big - max %d\n", long_val, MAX_MTU);
1991 if (l->lcp.cfg.mtu > *change)
1992 l->lcp.cfg.mtu = *change;
1996 if (strcasecmp(argp, "active") == 0)
1997 cx->physical->link.lcp.cfg.openmode = arg->argc > arg->argn+1 ?
1998 atoi(arg->argv[arg->argn+1]) : 1;
1999 else if (strcasecmp(argp, "passive") == 0)
2000 cx->physical->link.lcp.cfg.openmode = OPEN_PASSIVE;
2002 log_Printf(LogWARN, "%s: Invalid openmode\n", argp);
2008 strncpy(cx->cfg.phone.list, argp, sizeof cx->cfg.phone.list - 1);
2009 cx->cfg.phone.list[sizeof cx->cfg.phone.list - 1] = '\0';
2010 cx->phone.alt = cx->phone.next = NULL;
2014 strncpy(cx->cfg.script.hangup, argp, sizeof cx->cfg.script.hangup - 1);
2015 cx->cfg.script.hangup[sizeof cx->cfg.script.hangup - 1] = '\0';
2019 long_val = atol(argp);
2020 arg->bundle->cfg.ifqueue = long_val < 0 ? 0 : long_val;
2024 strncpy(cx->cfg.script.logout, argp, sizeof cx->cfg.script.logout - 1);
2025 cx->cfg.script.logout[sizeof cx->cfg.script.logout - 1] = '\0';
2028 case VAR_IDLETIMEOUT:
2029 if (arg->argc > arg->argn+2) {
2030 log_Printf(LogWARN, "Too many idle timeout values\n");
2032 } else if (arg->argc == arg->argn) {
2033 log_Printf(LogWARN, "Too few idle timeout values\n");
2036 unsigned long timeout, min;
2038 timeout = strtoul(argp, NULL, 10);
2039 min = arg->bundle->cfg.idle.min_timeout;
2040 if (arg->argc == arg->argn + 2)
2041 min = strtoul(arg->argv[arg->argn + 1], NULL, 10);
2042 bundle_SetIdleTimer(arg->bundle, timeout, min);
2048 if (arg->argc > arg->argn + 2) {
2049 log_Printf(LogWARN, "Too many RADIUS alive interval values\n");
2051 } else if (arg->argc == arg->argn) {
2052 log_Printf(LogWARN, "Too few RADIUS alive interval values\n");
2055 arg->bundle->radius.alive.interval = atoi(argp);
2056 if (arg->bundle->radius.alive.interval && !*arg->bundle->radius.cfg.file) {
2057 log_Printf(LogWARN, "rad_alive requires radius to be configured\n");
2059 } else if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED) {
2060 if (arg->bundle->radius.alive.interval)
2061 radius_StartTimer(arg->bundle);
2063 radius_StopTimer(&arg->bundle->radius);
2070 long_val = atol(argp);
2071 if (long_val < MIN_LQRPERIOD) {
2072 log_Printf(LogWARN, "%ld: Invalid lqr period - min %d\n",
2073 long_val, MIN_LQRPERIOD);
2076 l->lcp.cfg.lqrperiod = long_val;
2080 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2081 &cx->physical->link.lcp.cfg.fsm.timeout,
2082 &cx->physical->link.lcp.cfg.fsm.maxreq,
2083 &cx->physical->link.lcp.cfg.fsm.maxtrm, DEF_FSMTRIES);
2087 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2088 &cx->chap.auth.cfg.fsm.timeout,
2089 &cx->chap.auth.cfg.fsm.maxreq, NULL, DEF_FSMAUTHTRIES);
2093 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2094 &cx->pap.cfg.fsm.timeout, &cx->pap.cfg.fsm.maxreq,
2095 NULL, DEF_FSMAUTHTRIES);
2099 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2100 &l->ccp.cfg.fsm.timeout, &l->ccp.cfg.fsm.maxreq,
2101 &l->ccp.cfg.fsm.maxtrm, DEF_FSMTRIES);
2105 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2106 &arg->bundle->ncp.ipcp.cfg.fsm.timeout,
2107 &arg->bundle->ncp.ipcp.cfg.fsm.maxreq,
2108 &arg->bundle->ncp.ipcp.cfg.fsm.maxtrm, DEF_FSMTRIES);
2112 case VAR_IPV6CPRETRY:
2113 res = SetRetry(arg->argc - arg->argn, arg->argv + arg->argn,
2114 &arg->bundle->ncp.ipv6cp.cfg.fsm.timeout,
2115 &arg->bundle->ncp.ipv6cp.cfg.fsm.maxreq,
2116 &arg->bundle->ncp.ipv6cp.cfg.fsm.maxtrm, DEF_FSMTRIES);
2122 if (param == VAR_DNS) {
2123 ipaddr = arg->bundle->ncp.ipcp.cfg.ns.dns;
2124 ipaddr[0].s_addr = ipaddr[1].s_addr = INADDR_NONE;
2126 ipaddr = arg->bundle->ncp.ipcp.cfg.ns.nbns;
2127 ipaddr[0].s_addr = ipaddr[1].s_addr = INADDR_ANY;
2130 if (arg->argc > arg->argn) {
2131 ncpaddr_aton(ncpaddr, &arg->bundle->ncp, arg->argv[arg->argn]);
2132 if (!ncpaddr_getip4(ncpaddr, ipaddr))
2134 if (arg->argc > arg->argn+1) {
2135 ncpaddr_aton(ncpaddr + 1, &arg->bundle->ncp, arg->argv[arg->argn + 1]);
2136 if (!ncpaddr_getip4(ncpaddr + 1, ipaddr + 1))
2140 if (ipaddr[0].s_addr == INADDR_ANY) {
2141 ipaddr[0] = ipaddr[1];
2142 ipaddr[1].s_addr = INADDR_ANY;
2144 if (ipaddr[0].s_addr == INADDR_NONE) {
2145 ipaddr[0] = ipaddr[1];
2146 ipaddr[1].s_addr = INADDR_NONE;
2152 cx->cfg.callback.opmask = 0;
2153 for (dummyint = arg->argn; dummyint < arg->argc; dummyint++) {
2154 if (!strcasecmp(arg->argv[dummyint], "auth"))
2155 cx->cfg.callback.opmask |= CALLBACK_BIT(CALLBACK_AUTH);
2156 else if (!strcasecmp(arg->argv[dummyint], "cbcp"))
2157 cx->cfg.callback.opmask |= CALLBACK_BIT(CALLBACK_CBCP);
2158 else if (!strcasecmp(arg->argv[dummyint], "e.164")) {
2159 if (dummyint == arg->argc - 1)
2160 log_Printf(LogWARN, "No E.164 arg (E.164 ignored) !\n");
2162 cx->cfg.callback.opmask |= CALLBACK_BIT(CALLBACK_E164);
2163 strncpy(cx->cfg.callback.msg, arg->argv[++dummyint],
2164 sizeof cx->cfg.callback.msg - 1);
2165 cx->cfg.callback.msg[sizeof cx->cfg.callback.msg - 1] = '\0';
2167 } else if (!strcasecmp(arg->argv[dummyint], "none"))
2168 cx->cfg.callback.opmask |= CALLBACK_BIT(CALLBACK_NONE);
2174 if (cx->cfg.callback.opmask == CALLBACK_BIT(CALLBACK_NONE))
2175 cx->cfg.callback.opmask = 0;
2179 cx->cfg.cbcp.delay = 0;
2180 *cx->cfg.cbcp.phone = '\0';
2181 cx->cfg.cbcp.fsmretry = DEF_FSMRETRY;
2182 if (arg->argc > arg->argn) {
2183 strncpy(cx->cfg.cbcp.phone, arg->argv[arg->argn],
2184 sizeof cx->cfg.cbcp.phone - 1);
2185 cx->cfg.cbcp.phone[sizeof cx->cfg.cbcp.phone - 1] = '\0';
2186 if (arg->argc > arg->argn + 1) {
2187 cx->cfg.cbcp.delay = atoi(arg->argv[arg->argn + 1]);
2188 if (arg->argc > arg->argn + 2) {
2189 long_val = atol(arg->argv[arg->argn + 2]);
2190 if (long_val < MIN_FSMRETRY)
2191 log_Printf(LogWARN, "%ld: Invalid CBCP FSM retry period - min %d\n",
2192 long_val, MIN_FSMRETRY);
2194 cx->cfg.cbcp.fsmretry = long_val;
2201 arg->bundle->cfg.choked.timeout = atoi(argp);
2202 if (arg->bundle->cfg.choked.timeout <= 0)
2203 arg->bundle->cfg.choked.timeout = CHOKED_TIMEOUT;
2207 long_val = atol(argp);
2208 arg->bundle->ncp.cfg.sendpipe = long_val;
2212 long_val = atol(argp);
2213 arg->bundle->ncp.cfg.recvpipe = long_val;
2219 *arg->bundle->radius.cfg.file = '\0';
2220 else if (access(argp, R_OK)) {
2221 log_Printf(LogWARN, "%s: %s\n", argp, strerror(errno));
2225 strncpy(arg->bundle->radius.cfg.file, argp,
2226 sizeof arg->bundle->radius.cfg.file - 1);
2227 arg->bundle->radius.cfg.file
2228 [sizeof arg->bundle->radius.cfg.file - 1] = '\0';
2235 if (strcasecmp(argp, "off")) {
2236 long_val = atol(argp);
2239 cx->physical->cfg.cd.delay = long_val;
2240 cx->physical->cfg.cd.necessity = argp[strlen(argp)-1] == '!' ?
2241 CD_REQUIRED : CD_VARIABLE;
2243 cx->physical->cfg.cd.necessity = CD_NOTREQUIRED;
2245 cx->physical->cfg.cd.delay = 0;
2246 cx->physical->cfg.cd.necessity = CD_DEFAULT;
2251 if (arg->argc == arg->argn + 1)
2252 res = physical_SetParity(arg->cx->physical, argp);
2254 log_Printf(LogWARN, "Parity value must be odd, even or none\n");
2260 if (strcasecmp(argp, "on") == 0)
2261 physical_SetRtsCts(arg->cx->physical, 1);
2262 else if (strcasecmp(argp, "off") == 0)
2263 physical_SetRtsCts(arg->cx->physical, 0);
2265 log_Printf(LogWARN, "RTS/CTS value must be on or off\n");
2271 if (arg->argn == arg->argc) {
2272 ncp_SetUrgentTOS(&arg->bundle->ncp);
2273 ncp_ClearUrgentTcpPorts(&arg->bundle->ncp);
2274 ncp_ClearUrgentUdpPorts(&arg->bundle->ncp);
2275 } else if (!strcasecmp(arg->argv[arg->argn], "udp")) {
2276 ncp_SetUrgentTOS(&arg->bundle->ncp);
2277 if (arg->argn == arg->argc - 1)
2278 ncp_ClearUrgentUdpPorts(&arg->bundle->ncp);
2279 else for (f = arg->argn + 1; f < arg->argc; f++)
2280 if (*arg->argv[f] == '+')
2281 ncp_AddUrgentUdpPort(&arg->bundle->ncp, atoi(arg->argv[f] + 1));
2282 else if (*arg->argv[f] == '-')
2283 ncp_RemoveUrgentUdpPort(&arg->bundle->ncp, atoi(arg->argv[f] + 1));
2286 ncp_ClearUrgentUdpPorts(&arg->bundle->ncp);
2287 ncp_AddUrgentUdpPort(&arg->bundle->ncp, atoi(arg->argv[f]));
2289 } else if (arg->argn == arg->argc - 1 &&
2290 !strcasecmp(arg->argv[arg->argn], "none")) {
2291 ncp_ClearUrgentTcpPorts(&arg->bundle->ncp);
2292 ncp_ClearUrgentUdpPorts(&arg->bundle->ncp);
2293 ncp_ClearUrgentTOS(&arg->bundle->ncp);
2294 } else if (!strcasecmp(arg->argv[arg->argn], "length")) {
2295 if (arg->argn == arg->argc - 1)
2296 ncp_SetUrgentTcpLen(&arg->bundle->ncp, 0);
2298 ncp_SetUrgentTcpLen(&arg->bundle->ncp, atoi(arg->argv[arg->argn + 1]));
2300 ncp_SetUrgentTOS(&arg->bundle->ncp);
2302 if (!strcasecmp(arg->argv[first], "tcp") && ++first == arg->argc)
2303 ncp_ClearUrgentTcpPorts(&arg->bundle->ncp);
2305 for (f = first; f < arg->argc; f++)
2306 if (*arg->argv[f] == '+')
2307 ncp_AddUrgentTcpPort(&arg->bundle->ncp, atoi(arg->argv[f] + 1));
2308 else if (*arg->argv[f] == '-')
2309 ncp_RemoveUrgentTcpPort(&arg->bundle->ncp, atoi(arg->argv[f] + 1));
2312 ncp_ClearUrgentTcpPorts(&arg->bundle->ncp);
2313 ncp_AddUrgentTcpPort(&arg->bundle->ncp, atoi(arg->argv[f]));
2319 if (strcasecmp(argp, "3Com") == 0)
2320 physical_SetPPPoEnonstandard(arg->cx->physical, 1);
2321 else if (strcasecmp(argp, "standard") == 0)
2322 physical_SetPPPoEnonstandard(arg->cx->physical, 0);
2324 log_Printf(LogWARN, "PPPoE standard value must be \"standard\" or \"3Com\"\n");
2331 if (strcasecmp(argp, "default") == 0)
2332 arg->bundle->radius.port_id_type = RPI_DEFAULT;
2333 else if (strcasecmp(argp, "pid") == 0)
2334 arg->bundle->radius.port_id_type = RPI_PID;
2335 else if (strcasecmp(argp, "ifnum") == 0)
2336 arg->bundle->radius.port_id_type = RPI_IFNUM;
2337 else if (strcasecmp(argp, "tunnum") == 0)
2338 arg->bundle->radius.port_id_type = RPI_TUNNUM;
2341 "RADIUS port id must be one of \"default\", \"pid\", \"ifnum\" or \"tunnum\"\n");
2345 if (arg->bundle->radius.port_id_type && !*arg->bundle->radius.cfg.file) {
2346 log_Printf(LogWARN, "rad_port_id requires radius to be configured\n");
2357 static struct cmdtab const SetCommands[] = {
2358 {"accmap", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2359 "accmap value", "set accmap hex-value", (const void *)VAR_ACCMAP},
2360 {"authkey", "key", SetVariable, LOCAL_AUTH,
2361 "authentication key", "set authkey|key key", (const void *)VAR_AUTHKEY},
2362 {"authname", NULL, SetVariable, LOCAL_AUTH,
2363 "authentication name", "set authname name", (const void *)VAR_AUTHNAME},
2364 {"autoload", NULL, SetVariable, LOCAL_AUTH,
2365 "auto link [de]activation", "set autoload maxtime maxload mintime minload",
2366 (const void *)VAR_AUTOLOAD},
2367 {"bandwidth", NULL, mp_SetDatalinkBandwidth, LOCAL_AUTH | LOCAL_CX,
2368 "datalink bandwidth", "set bandwidth value", NULL},
2369 {"callback", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2370 "callback control", "set callback [none|auth|cbcp|"
2371 "E.164 *|number[,number]...]...", (const void *)VAR_CALLBACK},
2372 {"cbcp", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2373 "CBCP control", "set cbcp [*|phone[,phone...] [delay [timeout]]]",
2374 (const void *)VAR_CBCP},
2375 {"ccpretry", "ccpretries", SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
2376 "CCP retries", "set ccpretry value [attempts]", (const void *)VAR_CCPRETRY},
2377 {"cd", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "Carrier delay requirement",
2378 "set cd value[!]", (const void *)VAR_CD},
2379 {"chapretry", "chapretries", SetVariable, LOCAL_AUTH | LOCAL_CX,
2380 "CHAP retries", "set chapretry value [attempts]",
2381 (const void *)VAR_CHAPRETRY},
2382 {"choked", NULL, SetVariable, LOCAL_AUTH,
2383 "choked timeout", "set choked [secs]", (const void *)VAR_CHOKED},
2384 {"ctsrts", "crtscts", SetVariable, LOCAL_AUTH | LOCAL_CX,
2385 "Use hardware flow control", "set ctsrts [on|off]",
2386 (const char *)VAR_CRTSCTS},
2387 {"deflate", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
2388 "deflate window sizes", "set deflate out-winsize in-winsize",
2389 (const void *) VAR_WINSIZE},
2391 {"mppe", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
2392 "MPPE key size and state", "set mppe [40|56|128|* [stateful|stateless|*]]",
2393 (const void *) VAR_MPPE},
2395 {"device", "line", SetVariable, LOCAL_AUTH | LOCAL_CX,
2396 "physical device name", "set device|line device-name[,device-name]",
2397 (const void *) VAR_DEVICE},
2398 {"dial", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2399 "dialing script", "set dial chat-script", (const void *) VAR_DIAL},
2400 {"dns", NULL, SetVariable, LOCAL_AUTH, "Domain Name Server",
2401 "set dns pri-addr [sec-addr]", (const void *)VAR_DNS},
2402 {"enddisc", NULL, mp_SetEnddisc, LOCAL_AUTH,
2403 "Endpoint Discriminator", "set enddisc [IP|magic|label|psn value]", NULL},
2404 {"escape", NULL, SetEscape, LOCAL_AUTH | LOCAL_CX,
2405 "escape characters", "set escape hex-digit ...", NULL},
2406 {"filter", NULL, filter_Set, LOCAL_AUTH,
2407 "packet filters", "set filter alive|dial|in|out rule-no permit|deny "
2408 "[src_addr[/width]] [dst_addr[/width]] [proto "
2409 "[src [lt|eq|gt port]] [dst [lt|eq|gt port]] [estab] [syn] [finrst]]", NULL},
2410 {"hangup", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2411 "hangup script", "set hangup chat-script", (const void *) VAR_HANGUP},
2412 {"ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH, "destination address",
2413 "set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]", NULL},
2414 {"ifqueue", NULL, SetVariable, LOCAL_AUTH, "interface queue",
2415 "set ifqueue packets", (const void *)VAR_IFQUEUE},
2416 {"ipcpretry", "ipcpretries", SetVariable, LOCAL_AUTH, "IPCP retries",
2417 "set ipcpretry value [attempts]", (const void *)VAR_IPCPRETRY},
2418 {"ipv6cpretry", "ipv6cpretries", SetVariable, LOCAL_AUTH, "IPV6CP retries",
2419 "set ipv6cpretry value [attempts]", (const void *)VAR_IPV6CPRETRY},
2420 {"lcpretry", "lcpretries", SetVariable, LOCAL_AUTH | LOCAL_CX, "LCP retries",
2421 "set lcpretry value [attempts]", (const void *)VAR_LCPRETRY},
2422 {"log", NULL, log_SetLevel, LOCAL_AUTH, "log level",
2423 "set log [local] [+|-]all|async|cbcp|ccp|chat|command|connect|debug|dns|hdlc|"
2424 "id0|ipcp|lcp|lqm|phase|physical|radius|sync|tcp/ip|timer|tun...", NULL},
2425 {"login", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2426 "login script", "set login chat-script", (const void *) VAR_LOGIN},
2427 {"logout", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2428 "logout script", "set logout chat-script", (const void *) VAR_LOGOUT},
2429 {"lqrperiod", "echoperiod", SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
2430 "LQR period", "set lqr/echo period value", (const void *)VAR_LQRPERIOD},
2431 {"mode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "mode value",
2432 "set mode interactive|auto|ddial|background", (const void *)VAR_MODE},
2433 {"mrru", NULL, SetVariable, LOCAL_AUTH, "MRRU value",
2434 "set mrru value", (const void *)VAR_MRRU},
2435 {"mru", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2436 "MRU value", "set mru [max[imum]] [value]", (const void *)VAR_MRU},
2437 {"mtu", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2438 "interface MTU value", "set mtu [max[imum]] [value]", (const void *)VAR_MTU},
2439 {"nbns", NULL, SetVariable, LOCAL_AUTH, "NetBIOS Name Server",
2440 "set nbns pri-addr [sec-addr]", (const void *)VAR_NBNS},
2441 {"openmode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "open mode",
2442 "set openmode active|passive [secs]", (const void *)VAR_OPENMODE},
2443 {"papretry", "papretries", SetVariable, LOCAL_AUTH | LOCAL_CX, "PAP retries",
2444 "set papretry value [attempts]", (const void *)VAR_PAPRETRY},
2445 {"parity", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "serial parity",
2446 "set parity [odd|even|none]", (const void *)VAR_PARITY},
2447 {"phone", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "telephone number(s)",
2448 "set phone phone1[:phone2[...]]", (const void *)VAR_PHONE},
2449 {"proctitle", "title", SetProcTitle, LOCAL_AUTH,
2450 "Process title", "set proctitle [value]", NULL},
2452 {"radius", NULL, SetVariable, LOCAL_AUTH,
2453 "RADIUS Config", "set radius cfgfile", (const void *)VAR_RADIUS},
2454 {"rad_alive", NULL, SetVariable, LOCAL_AUTH,
2455 "Raduis alive interval", "set rad_alive value",
2456 (const void *)VAR_RAD_ALIVE},
2457 {"rad_port_id", NULL, SetVariable, LOCAL_AUTH,
2458 "NAS-Port-Id", "set rad_port_id [default|pid|ifnum|tunnum]", (const void *)VAR_PORT_ID},
2460 {"reconnect", NULL, datalink_SetReconnect, LOCAL_AUTH | LOCAL_CX,
2461 "Reconnect timeout", "set reconnect value ntries", NULL},
2462 {"recvpipe", NULL, SetVariable, LOCAL_AUTH,
2463 "RECVPIPE value", "set recvpipe value", (const void *)VAR_RECVPIPE},
2464 {"redial", NULL, datalink_SetRedial, LOCAL_AUTH | LOCAL_CX,
2465 "Redial timeout", "set redial secs[+inc[-incmax]][.next] [attempts]", NULL},
2466 {"sendpipe", NULL, SetVariable, LOCAL_AUTH,
2467 "SENDPIPE value", "set sendpipe value", (const void *)VAR_SENDPIPE},
2468 {"server", "socket", SetServer, LOCAL_AUTH, "diagnostic port",
2469 "set server|socket TcpPort|LocalName|none|open|closed [password [mask]]",
2471 {"speed", NULL, SetModemSpeed, LOCAL_AUTH | LOCAL_CX,
2472 "physical speed", "set speed value|sync", NULL},
2473 {"stopped", NULL, SetStoppedTimeout, LOCAL_AUTH | LOCAL_CX,
2474 "STOPPED timeouts", "set stopped [LCPseconds [CCPseconds]]", NULL},
2475 {"timeout", NULL, SetVariable, LOCAL_AUTH, "Idle timeout",
2476 "set timeout idletime", (const void *)VAR_IDLETIMEOUT},
2477 {"urgent", NULL, SetVariable, LOCAL_AUTH, "urgent traffic",
2478 "set urgent [[tcp|udp] [+|-]port...]|[length len]", (const void *)VAR_URGENT},
2479 {"vj", NULL, ipcp_vjset, LOCAL_AUTH,
2480 "vj values", "set vj slots|slotcomp [value]", NULL},
2481 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
2482 "Display this message", "set help|? [command]", SetCommands},
2483 {"pppoe", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
2484 "Connect using standard/3Com mode", "set pppoe [standard|3Com]",
2485 (const char *)VAR_PPPOE},
2486 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
2490 SetCommand(struct cmdargs const *arg)
2492 if (arg->argc > arg->argn)
2493 FindExec(arg->bundle, SetCommands, arg->argc, arg->argn, arg->argv,
2494 arg->prompt, arg->cx);
2495 else if (arg->prompt)
2496 prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
2499 log_Printf(LogWARN, "set command must have arguments\n");
2505 AddCommand(struct cmdargs const *arg)
2508 struct ncprange dest;
2509 struct in_addr host;
2511 struct in6_addr host6;
2513 int dest_default, gw_arg, addrs;
2515 if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
2520 if (arg->argc == arg->argn + 2) {
2521 if (!strcasecmp(arg->argv[arg->argn], "default"))
2524 if (!ncprange_aton(&dest, &arg->bundle->ncp, arg->argv[arg->argn]))
2526 if (!strncasecmp(arg->argv[arg->argn], "MYADDR", 6))
2527 addrs = ROUTE_DSTMYADDR;
2528 else if (!strncasecmp(arg->argv[arg->argn], "MYADDR6", 7))
2529 addrs = ROUTE_DSTMYADDR6;
2530 else if (!strncasecmp(arg->argv[arg->argn], "HISADDR", 7))
2531 addrs = ROUTE_DSTHISADDR;
2532 else if (!strncasecmp(arg->argv[arg->argn], "HISADDR6", 8))
2533 addrs = ROUTE_DSTHISADDR6;
2534 else if (!strncasecmp(arg->argv[arg->argn], "DNS0", 4))
2535 addrs = ROUTE_DSTDNS0;
2536 else if (!strncasecmp(arg->argv[arg->argn], "DNS1", 4))
2537 addrs = ROUTE_DSTDNS1;
2541 if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0) {
2542 addrs = ROUTE_DSTMYADDR;
2543 host = arg->bundle->ncp.ipcp.my_ip;
2544 } else if (strcasecmp(arg->argv[arg->argn], "HISADDR") == 0) {
2545 addrs = ROUTE_DSTHISADDR;
2546 host = arg->bundle->ncp.ipcp.peer_ip;
2547 } else if (strcasecmp(arg->argv[arg->argn], "DNS0") == 0) {
2548 addrs = ROUTE_DSTDNS0;
2549 host = arg->bundle->ncp.ipcp.ns.dns[0];
2550 } else if (strcasecmp(arg->argv[arg->argn], "DNS1") == 0) {
2551 addrs = ROUTE_DSTDNS1;
2552 host = arg->bundle->ncp.ipcp.ns.dns[1];
2554 host = GetIpAddr(arg->argv[arg->argn]);
2555 if (host.s_addr == INADDR_NONE) {
2556 log_Printf(LogWARN, "%s: Invalid destination address\n",
2557 arg->argv[arg->argn]);
2561 ncprange_setip4(&dest, host, GetIpAddr(arg->argv[arg->argn + 1]));
2565 if (strcasecmp(arg->argv[arg->argn + gw_arg], "HISADDR") == 0) {
2566 ncpaddr_setip4(&gw, arg->bundle->ncp.ipcp.peer_ip);
2567 addrs |= ROUTE_GWHISADDR;
2569 } else if (strcasecmp(arg->argv[arg->argn + gw_arg], "HISADDR6") == 0) {
2570 if (!ncpaddr_getip6(&arg->bundle->ncp.ipv6cp.hisaddr, &host6))
2571 memset(&host6, '\0', sizeof host6);
2572 ncpaddr_setip6(&gw, &host6);
2573 addrs |= ROUTE_GWHISADDR6;
2576 if (!ncpaddr_aton(&gw, &arg->bundle->ncp, arg->argv[arg->argn + gw_arg])) {
2577 log_Printf(LogWARN, "%s: Invalid gateway address\n",
2578 arg->argv[arg->argn + gw_arg]);
2584 ncprange_setdefault(&dest, ncpaddr_family(&gw));
2586 if (rt_Set(arg->bundle, RTM_ADD, &dest, &gw, arg->cmd->args ? 1 : 0,
2587 ((addrs & ROUTE_GWHISADDR) || (addrs & ROUTE_GWHISADDR6)) ? 1 : 0)
2588 && addrs != ROUTE_STATIC)
2589 route_Add(&arg->bundle->ncp.route, addrs, &dest, &gw);
2595 DeleteCommand(struct cmdargs const *arg)
2597 struct ncprange dest;
2600 if (arg->argc == arg->argn+1) {
2601 if(strcasecmp(arg->argv[arg->argn], "all") == 0) {
2602 route_IfDelete(arg->bundle, 0);
2603 route_DeleteAll(&arg->bundle->ncp.route);
2606 if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0) {
2607 ncprange_setip4host(&dest, arg->bundle->ncp.ipcp.my_ip);
2608 addrs = ROUTE_DSTMYADDR;
2610 } else if (strcasecmp(arg->argv[arg->argn], "MYADDR6") == 0) {
2611 ncprange_sethost(&dest, &arg->bundle->ncp.ipv6cp.myaddr);
2612 addrs = ROUTE_DSTMYADDR6;
2614 } else if (strcasecmp(arg->argv[arg->argn], "HISADDR") == 0) {
2615 ncprange_setip4host(&dest, arg->bundle->ncp.ipcp.peer_ip);
2616 addrs = ROUTE_DSTHISADDR;
2618 } else if (strcasecmp(arg->argv[arg->argn], "HISADDR6") == 0) {
2619 ncprange_sethost(&dest, &arg->bundle->ncp.ipv6cp.hisaddr);
2620 addrs = ROUTE_DSTHISADDR6;
2622 } else if (strcasecmp(arg->argv[arg->argn], "DNS0") == 0) {
2623 ncprange_setip4host(&dest, arg->bundle->ncp.ipcp.ns.dns[0]);
2624 addrs = ROUTE_DSTDNS0;
2625 } else if (strcasecmp(arg->argv[arg->argn], "DNS1") == 0) {
2626 ncprange_setip4host(&dest, arg->bundle->ncp.ipcp.ns.dns[1]);
2627 addrs = ROUTE_DSTDNS1;
2629 ncprange_aton(&dest, &arg->bundle->ncp, arg->argv[arg->argn]);
2630 addrs = ROUTE_STATIC;
2632 rt_Set(arg->bundle, RTM_DELETE, &dest, NULL, arg->cmd->args ? 1 : 0, 0);
2633 route_Delete(&arg->bundle->ncp.route, addrs, &dest);
2643 NatEnable(struct cmdargs const *arg)
2645 if (arg->argc == arg->argn+1) {
2646 if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
2647 if (!arg->bundle->NatEnabled) {
2648 if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED)
2649 LibAliasSetAddress(la, arg->bundle->ncp.ipcp.my_ip);
2650 arg->bundle->NatEnabled = 1;
2653 } else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
2654 arg->bundle->NatEnabled = 0;
2655 opt_disable(arg->bundle, OPT_IFACEALIAS);
2656 /* Don't iface_Clear() - there may be manually configured addresses */
2666 NatOption(struct cmdargs const *arg)
2668 long param = (long)arg->cmd->args;
2670 if (arg->argc == arg->argn+1) {
2671 if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
2672 if (arg->bundle->NatEnabled) {
2673 LibAliasSetMode(la, param, param);
2676 log_Printf(LogWARN, "nat not enabled\n");
2677 } else if (strcmp(arg->argv[arg->argn], "no") == 0) {
2678 if (arg->bundle->NatEnabled) {
2679 LibAliasSetMode(la, 0, param);
2682 log_Printf(LogWARN, "nat not enabled\n");
2687 #endif /* #ifndef NONAT */
2690 LinkCommand(struct cmdargs const *arg)
2692 if (arg->argc > arg->argn+1) {
2693 char namelist[LINE_LEN];
2694 struct datalink *cx;
2698 if (!strcmp(arg->argv[arg->argn], "*")) {
2699 struct datalink *dl;
2701 cx = arg->bundle->links;
2703 /* Watch it, the command could be a ``remove'' */
2705 FindExec(arg->bundle, Commands, arg->argc, arg->argn+1, arg->argv,
2707 for (cx = arg->bundle->links; cx; cx = cx->next)
2709 break; /* Pointer's still valid ! */
2712 strncpy(namelist, arg->argv[arg->argn], sizeof namelist - 1);
2713 namelist[sizeof namelist - 1] = '\0';
2714 for(name = strtok(namelist, ", "); name; name = strtok(NULL,", "))
2715 if (!bundle2datalink(arg->bundle, name)) {
2716 log_Printf(LogWARN, "link: %s: Invalid link name\n", name);
2720 strncpy(namelist, arg->argv[arg->argn], sizeof namelist - 1);
2721 namelist[sizeof namelist - 1] = '\0';
2722 for(name = strtok(namelist, ", "); name; name = strtok(NULL,", ")) {
2723 cx = bundle2datalink(arg->bundle, name);
2725 FindExec(arg->bundle, Commands, arg->argc, arg->argn+1, arg->argv,
2728 log_Printf(LogWARN, "link: %s: Invalidated link name !\n", name);
2736 log_Printf(LogWARN, "usage: %s\n", arg->cmd->syntax);
2741 command_ChooseLink(struct cmdargs const *arg)
2744 return &arg->cx->physical->link;
2745 else if (!arg->bundle->ncp.mp.cfg.mrru) {
2746 struct datalink *dl = bundle2datalink(arg->bundle, NULL);
2748 return &dl->physical->link;
2750 return &arg->bundle->ncp.mp.link;
2754 ident_cmd(const char *cmd, unsigned *keep, unsigned *add)
2763 *add = NEG_ACCEPTED;
2777 *keep = NEG_HISMASK;
2787 *keep = NEG_HISMASK;
2798 OptSet(struct cmdargs const *arg)
2800 int opt = (int)(long)arg->cmd->args;
2801 unsigned keep; /* Keep this opt */
2802 unsigned add; /* Add this opt */
2804 if (ident_cmd(arg->argv[arg->argn - 2], &keep, &add) == NULL)
2808 if (add == NEG_ENABLED && opt == OPT_IPV6CP && !probe.ipv6_available) {
2809 log_Printf(LogWARN, "IPv6 is not available on this machine\n");
2813 if (!add && ((opt == OPT_NAS_IP_ADDRESS &&
2814 !Enabled(arg->bundle, OPT_NAS_IDENTIFIER)) ||
2815 (opt == OPT_NAS_IDENTIFIER &&
2816 !Enabled(arg->bundle, OPT_NAS_IP_ADDRESS)))) {
2818 "Cannot disable both NAS-IP-Address and NAS-Identifier\n");
2823 opt_enable(arg->bundle, opt);
2825 opt_disable(arg->bundle, opt);
2831 IfaceAliasOptSet(struct cmdargs const *arg)
2833 unsigned long long save = arg->bundle->cfg.optmask;
2834 int result = OptSet(arg);
2837 if (Enabled(arg->bundle, OPT_IFACEALIAS) && !arg->bundle->NatEnabled) {
2838 arg->bundle->cfg.optmask = save;
2839 log_Printf(LogWARN, "Cannot enable iface-alias without NAT\n");
2847 NegotiateSet(struct cmdargs const *arg)
2849 long param = (long)arg->cmd->args;
2850 struct link *l = command_ChooseLink(arg); /* LOCAL_CX_OPT uses this */
2851 struct datalink *cx = arg->cx; /* LOCAL_CX uses this */
2853 unsigned keep; /* Keep these bits */
2854 unsigned add; /* Add these bits */
2856 if ((cmd = ident_cmd(arg->argv[arg->argn-2], &keep, &add)) == NULL)
2859 if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
2860 log_Printf(LogWARN, "%s %s: No context (use the `link' command)\n",
2861 cmd, arg->cmd->name);
2863 } else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
2864 log_Printf(LogWARN, "%s %s: Redundant context (%s) ignored\n",
2865 cmd, arg->cmd->name, cx->name);
2871 cx->physical->link.lcp.cfg.acfcomp &= keep;
2872 cx->physical->link.lcp.cfg.acfcomp |= add;
2875 cx->physical->link.lcp.cfg.chap05 &= keep;
2876 cx->physical->link.lcp.cfg.chap05 |= add;
2880 cx->physical->link.lcp.cfg.chap80nt &= keep;
2881 cx->physical->link.lcp.cfg.chap80nt |= add;
2884 cx->physical->link.lcp.cfg.chap80lm &= keep;
2885 cx->physical->link.lcp.cfg.chap80lm |= add;
2888 cx->physical->link.lcp.cfg.chap81 &= keep;
2889 cx->physical->link.lcp.cfg.chap81 |= add;
2892 l->ccp.cfg.neg[CCP_NEG_MPPE] &= keep;
2893 l->ccp.cfg.neg[CCP_NEG_MPPE] |= add;
2897 l->ccp.cfg.neg[CCP_NEG_DEFLATE] &= keep;
2898 l->ccp.cfg.neg[CCP_NEG_DEFLATE] |= add;
2901 arg->bundle->ncp.ipcp.cfg.ns.dns_neg &= keep;
2902 arg->bundle->ncp.ipcp.cfg.ns.dns_neg |= add;
2904 case NEG_ECHO: /* probably misplaced in this function ! */
2905 if (cx->physical->link.lcp.cfg.echo && !add) {
2906 cx->physical->link.lcp.cfg.echo = 0;
2907 cx->physical->hdlc.lqm.method &= ~LQM_ECHO;
2908 if (cx->physical->hdlc.lqm.method & LQM_ECHO &&
2909 !cx->physical->link.lcp.want_lqrperiod &&
2910 cx->physical->hdlc.lqm.timer.load) {
2911 cx->physical->hdlc.lqm.timer.load = 0;
2912 lqr_StopTimer(cx->physical);
2914 } else if (!cx->physical->link.lcp.cfg.echo && add) {
2915 cx->physical->link.lcp.cfg.echo = 1;
2916 cx->physical->hdlc.lqm.method |= LQM_ECHO;
2917 cx->physical->hdlc.lqm.timer.load =
2918 cx->physical->link.lcp.cfg.lqrperiod * SECTICKS;
2919 if (cx->physical->link.lcp.fsm.state == ST_OPENED)
2920 (*cx->physical->hdlc.lqm.timer.func)(&cx->physical->link.lcp);
2924 arg->bundle->ncp.mp.cfg.negenddisc &= keep;
2925 arg->bundle->ncp.mp.cfg.negenddisc |= add;
2928 cx->physical->link.lcp.cfg.lqr &= keep;
2929 cx->physical->link.lcp.cfg.lqr |= add;
2932 cx->physical->link.lcp.cfg.pap &= keep;
2933 cx->physical->link.lcp.cfg.pap |= add;
2935 case NEG_PPPDDEFLATE:
2936 l->ccp.cfg.neg[CCP_NEG_DEFLATE24] &= keep;
2937 l->ccp.cfg.neg[CCP_NEG_DEFLATE24] |= add;
2940 l->ccp.cfg.neg[CCP_NEG_PRED1] &= keep;
2941 l->ccp.cfg.neg[CCP_NEG_PRED1] |= add;
2944 cx->physical->link.lcp.cfg.protocomp &= keep;
2945 cx->physical->link.lcp.cfg.protocomp |= add;
2948 switch (bundle_Phase(arg->bundle)) {
2951 case PHASE_ESTABLISH:
2952 /* Make sure none of our links are DATALINK_LCP or greater */
2953 if (bundle_HighestState(arg->bundle) >= DATALINK_LCP) {
2954 log_Printf(LogWARN, "shortseq: Only changeable before"
2955 " LCP negotiations\n");
2960 log_Printf(LogWARN, "shortseq: Only changeable at phase"
2961 " DEAD/ESTABLISH\n");
2964 arg->bundle->ncp.mp.cfg.shortseq &= keep;
2965 arg->bundle->ncp.mp.cfg.shortseq |= add;
2968 arg->bundle->ncp.ipcp.cfg.vj.neg &= keep;
2969 arg->bundle->ncp.ipcp.cfg.vj.neg |= add;
2976 static struct cmdtab const NegotiateCommands[] = {
2977 {"echo", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX, "Send echo requests",
2978 "disable|enable", (const void *)NEG_ECHO},
2979 {"filter-decapsulation", NULL, OptSet, LOCAL_AUTH,
2980 "filter on PPPoUDP payloads", "disable|enable",
2981 (const void *)OPT_FILTERDECAP},
2982 {"force-scripts", NULL, OptSet, LOCAL_AUTH,
2983 "Force execution of the configured chat scripts", "disable|enable",
2984 (const void *)OPT_FORCE_SCRIPTS},
2985 {"idcheck", NULL, OptSet, LOCAL_AUTH, "Check FSM reply ids",
2986 "disable|enable", (const void *)OPT_IDCHECK},
2987 {"iface-alias", NULL, IfaceAliasOptSet, LOCAL_AUTH,
2988 "retain interface addresses", "disable|enable",
2989 (const void *)OPT_IFACEALIAS},
2991 {"ipcp", NULL, OptSet, LOCAL_AUTH, "IP Network Control Protocol",
2992 "disable|enable", (const void *)OPT_IPCP},
2993 {"ipv6cp", NULL, OptSet, LOCAL_AUTH, "IPv6 Network Control Protocol",
2994 "disable|enable", (const void *)OPT_IPV6CP},
2996 {"keep-session", NULL, OptSet, LOCAL_AUTH, "Retain device session leader",
2997 "disable|enable", (const void *)OPT_KEEPSESSION},
2998 {"loopback", NULL, OptSet, LOCAL_AUTH, "Loop packets for local iface",
2999 "disable|enable", (const void *)OPT_LOOPBACK},
3000 {"nas-ip-address", NULL, OptSet, LOCAL_AUTH, "Send NAS-IP-Address to RADIUS",
3001 "disable|enable", (const void *)OPT_NAS_IP_ADDRESS},
3002 {"nas-identifier", NULL, OptSet, LOCAL_AUTH, "Send NAS-Identifier to RADIUS",
3003 "disable|enable", (const void *)OPT_NAS_IDENTIFIER},
3004 {"passwdauth", NULL, OptSet, LOCAL_AUTH, "Use passwd file",
3005 "disable|enable", (const void *)OPT_PASSWDAUTH},
3006 {"proxy", NULL, OptSet, LOCAL_AUTH, "Create a proxy ARP entry",
3007 "disable|enable", (const void *)OPT_PROXY},
3008 {"proxyall", NULL, OptSet, LOCAL_AUTH, "Proxy ARP for all remote hosts",
3009 "disable|enable", (const void *)OPT_PROXYALL},
3010 {"sroutes", NULL, OptSet, LOCAL_AUTH, "Use sticky routes",
3011 "disable|enable", (const void *)OPT_SROUTES},
3012 {"tcpmssfixup", "mssfixup", OptSet, LOCAL_AUTH, "Modify MSS options",
3013 "disable|enable", (const void *)OPT_TCPMSSFIXUP},
3014 {"throughput", NULL, OptSet, LOCAL_AUTH, "Rolling throughput",
3015 "disable|enable", (const void *)OPT_THROUGHPUT},
3016 {"utmp", NULL, OptSet, LOCAL_AUTH, "Log connections in utmp",
3017 "disable|enable", (const void *)OPT_UTMP},
3020 #define NEG_OPT_MAX 17 /* accept/deny allowed below and not above */
3022 #define NEG_OPT_MAX 15
3025 {"acfcomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3026 "Address & Control field compression", "accept|deny|disable|enable",
3027 (const void *)NEG_ACFCOMP},
3028 {"chap", "chap05", NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3029 "Challenge Handshake Authentication Protocol", "accept|deny|disable|enable",
3030 (const void *)NEG_CHAP05},
3032 {"mschap", "chap80nt", NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3033 "Microsoft (NT) CHAP", "accept|deny|disable|enable",
3034 (const void *)NEG_CHAP80},
3035 {"LANMan", "chap80lm", NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3036 "Microsoft (NT) CHAP", "accept|deny|disable|enable",
3037 (const void *)NEG_CHAP80LM},
3038 {"mschapv2", "chap81", NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3039 "Microsoft CHAP v2", "accept|deny|disable|enable",
3040 (const void *)NEG_CHAP81},
3041 {"mppe", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
3042 "MPPE encryption", "accept|deny|disable|enable",
3043 (const void *)NEG_MPPE},
3045 {"deflate", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
3046 "Deflate compression", "accept|deny|disable|enable",
3047 (const void *)NEG_DEFLATE},
3048 {"deflate24", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
3049 "Deflate (type 24) compression", "accept|deny|disable|enable",
3050 (const void *)NEG_PPPDDEFLATE},
3051 {"dns", NULL, NegotiateSet, LOCAL_AUTH,
3052 "DNS specification", "accept|deny|disable|enable", (const void *)NEG_DNS},
3053 {"enddisc", NULL, NegotiateSet, LOCAL_AUTH, "ENDDISC negotiation",
3054 "accept|deny|disable|enable", (const void *)NEG_ENDDISC},
3055 {"lqr", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3056 "Link Quality Reports", "accept|deny|disable|enable",
3057 (const void *)NEG_LQR},
3058 {"pap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3059 "Password Authentication protocol", "accept|deny|disable|enable",
3060 (const void *)NEG_PAP},
3061 {"pred1", "predictor1", NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
3062 "Predictor 1 compression", "accept|deny|disable|enable",
3063 (const void *)NEG_PRED1},
3064 {"protocomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
3065 "Protocol field compression", "accept|deny|disable|enable",
3066 (const void *)NEG_PROTOCOMP},
3067 {"shortseq", NULL, NegotiateSet, LOCAL_AUTH,
3068 "MP Short Sequence Numbers", "accept|deny|disable|enable",
3069 (const void *)NEG_SHORTSEQ},
3070 {"vjcomp", NULL, NegotiateSet, LOCAL_AUTH,
3071 "Van Jacobson header compression", "accept|deny|disable|enable",
3072 (const void *)NEG_VJCOMP},
3073 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
3074 "Display this message", "accept|deny|disable|enable help|? [value]",
3076 {NULL, NULL, NULL, 0, NULL, NULL, NULL},
3080 NegotiateCommand(struct cmdargs const *arg)
3082 if (arg->argc > arg->argn) {
3083 char const *argv[3];
3087 if ((argv[0] = ident_cmd(arg->argv[arg->argn-1], &keep, &add)) == NULL)
3091 for (n = arg->argn; n < arg->argc; n++) {
3092 argv[1] = arg->argv[n];
3093 FindExec(arg->bundle, NegotiateCommands + (keep == NEG_HISMASK ?
3094 0 : NEG_OPT_MAX), 2, 1, argv, arg->prompt, arg->cx);
3096 } else if (arg->prompt)
3097 prompt_Printf(arg->prompt, "Use `%s ?' to get a list.\n",
3098 arg->argv[arg->argn-1]);
3100 log_Printf(LogWARN, "%s command must have arguments\n",
3101 arg->argv[arg->argn] );
3107 command_ShowNegval(unsigned val)
3110 case 1: return "disabled & accepted";
3111 case 2: return "enabled & denied";
3112 case 3: return "enabled & accepted";
3114 return "disabled & denied";
3118 ClearCommand(struct cmdargs const *arg)
3120 struct pppThroughput *t;
3121 struct datalink *cx;
3124 if (arg->argc < arg->argn + 1)
3127 if (strcasecmp(arg->argv[arg->argn], "physical") == 0) {
3130 cx = bundle2datalink(arg->bundle, NULL);
3132 log_Printf(LogWARN, "A link must be specified for ``clear physical''\n");
3135 t = &cx->physical->link.stats.total;
3136 } else if (strcasecmp(arg->argv[arg->argn], "ipcp") == 0)
3137 t = &arg->bundle->ncp.ipcp.throughput;
3139 else if (strcasecmp(arg->argv[arg->argn], "ipv6cp") == 0)
3140 t = &arg->bundle->ncp.ipv6cp.throughput;
3145 if (arg->argc > arg->argn + 1) {
3147 for (i = arg->argn + 1; i < arg->argc; i++)
3148 if (strcasecmp(arg->argv[i], "overall") == 0)
3149 clear_type |= THROUGHPUT_OVERALL;
3150 else if (strcasecmp(arg->argv[i], "current") == 0)
3151 clear_type |= THROUGHPUT_CURRENT;
3152 else if (strcasecmp(arg->argv[i], "peak") == 0)
3153 clear_type |= THROUGHPUT_PEAK;
3157 clear_type = THROUGHPUT_ALL;
3159 throughput_clear(t, clear_type, arg->prompt);
3164 RunListCommand(struct cmdargs const *arg)
3166 const char *cmd = arg->argc ? arg->argv[arg->argc - 1] : "???";
3169 if (arg->cmd->args == NatCommands &&
3170 tolower(*arg->argv[arg->argn - 1]) == 'a') {
3172 prompt_Printf(arg->prompt, "The alias command is deprecated\n");
3174 log_Printf(LogWARN, "The alias command is deprecated\n");
3178 if (arg->argc > arg->argn)
3179 FindExec(arg->bundle, arg->cmd->args, arg->argc, arg->argn, arg->argv,
3180 arg->prompt, arg->cx);
3181 else if (arg->prompt)
3182 prompt_Printf(arg->prompt, "Use `%s help' to get a list or `%s help"
3183 " <option>' for syntax help.\n", cmd, cmd);
3185 log_Printf(LogWARN, "%s command must have arguments\n", cmd);
3191 IfaceNameCommand(struct cmdargs const *arg)
3195 if (arg->argc != n + 1)
3198 if (!iface_Name(arg->bundle->iface, arg->argv[n]))
3201 log_SetTun(arg->bundle->unit, arg->bundle->iface->name);
3206 IfaceAddCommand(struct cmdargs const *arg)
3208 struct ncpaddr peer, addr;
3209 struct ncprange ifa;
3210 struct in_addr mask;
3213 if (arg->argc == arg->argn + 1) {
3214 if (!ncprange_aton(&ifa, NULL, arg->argv[arg->argn]))
3216 ncpaddr_init(&peer);
3218 if (arg->argc == arg->argn + 2) {
3219 if (!ncprange_aton(&ifa, NULL, arg->argv[arg->argn]))
3222 } else if (arg->argc == arg->argn + 3) {
3223 if (!ncpaddr_aton(&addr, NULL, arg->argv[arg->argn]))
3225 if (ncpaddr_family(&addr) != AF_INET)
3227 ncprange_sethost(&ifa, &addr);
3228 if (!ncpaddr_aton(&addr, NULL, arg->argv[arg->argn + 1]))
3230 if (!ncpaddr_getip4(&addr, &mask))
3232 if (!ncprange_setip4mask(&ifa, mask))
3238 if (!ncpaddr_aton(&peer, NULL, arg->argv[arg->argn + n]))
3241 if (ncprange_family(&ifa) != ncpaddr_family(&peer)) {
3242 log_Printf(LogWARN, "IfaceAddCommand: src and dst address families"
3248 how = IFACE_ADD_LAST;
3250 how |= IFACE_FORCE_ADD;
3252 return !iface_Add(arg->bundle->iface, &arg->bundle->ncp, &ifa, &peer, how);
3256 IfaceDeleteCommand(struct cmdargs const *arg)
3259 struct in_addr ifa4;
3262 if (arg->argc != arg->argn + 1)
3265 if (!ncpaddr_aton(&ifa, NULL, arg->argv[arg->argn]))
3268 if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED &&
3269 ncpaddr_getip4(&ifa, &ifa4) &&
3270 arg->bundle->ncp.ipcp.my_ip.s_addr == ifa4.s_addr) {
3271 log_Printf(LogWARN, "%s: Cannot remove active interface address\n",
3272 ncpaddr_ntoa(&ifa));
3276 ok = iface_Delete(arg->bundle->iface, &arg->bundle->ncp, &ifa);
3280 else if (arg->prompt)
3281 prompt_Printf(arg->prompt, "%s: No such interface address\n",
3282 ncpaddr_ntoa(&ifa));
3284 log_Printf(LogWARN, "%s: No such interface address\n",
3285 ncpaddr_ntoa(&ifa));
3292 IfaceClearCommand(struct cmdargs const *arg)
3297 if (arg->argc == arg->argn + 1) {
3298 if (strcasecmp(arg->argv[arg->argn], "inet") == 0)
3301 else if (strcasecmp(arg->argv[arg->argn], "inet6") == 0)
3306 } else if (arg->argc != arg->argn)
3309 how = arg->bundle->ncp.ipcp.fsm.state == ST_OPENED ||
3310 arg->bundle->phys_type.all & PHYS_AUTO ?
3311 IFACE_CLEAR_ALIASES : IFACE_CLEAR_ALL;
3312 iface_Clear(arg->bundle->iface, &arg->bundle->ncp, family, how);
3318 SetProcTitle(struct cmdargs const *arg)
3320 static char title[LINE_LEN];
3321 char *argv[MAXARGS];
3322 int argc = arg->argc - arg->argn;
3324 if (arg->argc <= arg->argn) {
3329 if ((unsigned)argc >= sizeof argv / sizeof argv[0]) {
3330 argc = sizeof argv / sizeof argv[0] - 1;
3331 log_Printf(LogWARN, "Truncating proc title to %d args\n", argc);
3333 command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid());
3334 Concatinate(title, sizeof title, argc, (const char *const *)argv);
3336 command_Free(argc, argv);