Deleted Added
full compact
command.c (40482) command.c (40561)
1/*
2 * PPP User command processing module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP User command processing module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: command.c,v 1.166 1998/09/17 00:45:26 brian Exp $
20 * $Id: command.c,v 1.167 1998/10/17 12:28:05 brian Exp $
21 *
22 */
23#include <sys/types.h>
24#include <netinet/in_systm.h>
25#include <netinet/in.h>
26#include <netinet/ip.h>
27#include <arpa/inet.h>
28#include <sys/socket.h>

--- 49 unchanged lines hidden (view full) ---

78#include "mp.h"
79#include "bundle.h"
80#include "server.h"
81#include "prompt.h"
82#include "chat.h"
83#include "chap.h"
84#include "cbcp.h"
85#include "datalink.h"
21 *
22 */
23#include <sys/types.h>
24#include <netinet/in_systm.h>
25#include <netinet/in.h>
26#include <netinet/ip.h>
27#include <arpa/inet.h>
28#include <sys/socket.h>

--- 49 unchanged lines hidden (view full) ---

78#include "mp.h"
79#include "bundle.h"
80#include "server.h"
81#include "prompt.h"
82#include "chat.h"
83#include "chap.h"
84#include "cbcp.h"
85#include "datalink.h"
86#include "iface.h"
86
87/* ``set'' values */
88#define VAR_AUTHKEY 0
89#define VAR_DIAL 1
90#define VAR_LOGIN 2
91#define VAR_AUTHNAME 3
92#define VAR_AUTOLOAD 4
93#define VAR_WINSIZE 5

--- 32 unchanged lines hidden (view full) ---

126#define NEG_PPPDDEFLATE 45
127#define NEG_PRED1 46
128#define NEG_PROTOCOMP 47
129#define NEG_SHORTSEQ 48
130#define NEG_VJCOMP 49
131#define NEG_DNS 50
132
133const char Version[] = "2.0";
87
88/* ``set'' values */
89#define VAR_AUTHKEY 0
90#define VAR_DIAL 1
91#define VAR_LOGIN 2
92#define VAR_AUTHNAME 3
93#define VAR_AUTOLOAD 4
94#define VAR_WINSIZE 5

--- 32 unchanged lines hidden (view full) ---

127#define NEG_PPPDDEFLATE 45
128#define NEG_PRED1 46
129#define NEG_PROTOCOMP 47
130#define NEG_SHORTSEQ 48
131#define NEG_VJCOMP 49
132#define NEG_DNS 50
133
134const char Version[] = "2.0";
134const char VersionDate[] = "$Date: 1998/09/17 00:45:26 $";
135const char VersionDate[] = "$Date: 1998/10/17 12:28:05 $";
135
136static int ShowCommand(struct cmdargs const *);
137static int TerminalCommand(struct cmdargs const *);
138static int QuitCommand(struct cmdargs const *);
139static int OpenCommand(struct cmdargs const *);
140static int CloseCommand(struct cmdargs const *);
141static int DownCommand(struct cmdargs const *);
136
137static int ShowCommand(struct cmdargs const *);
138static int TerminalCommand(struct cmdargs const *);
139static int QuitCommand(struct cmdargs const *);
140static int OpenCommand(struct cmdargs const *);
141static int CloseCommand(struct cmdargs const *);
142static int DownCommand(struct cmdargs const *);
142static int AllowCommand(struct cmdargs const *);
143static int SetCommand(struct cmdargs const *);
144static int LinkCommand(struct cmdargs const *);
145static int AddCommand(struct cmdargs const *);
146static int DeleteCommand(struct cmdargs const *);
147static int NegotiateCommand(struct cmdargs const *);
148static int ClearCommand(struct cmdargs const *);
143static int SetCommand(struct cmdargs const *);
144static int LinkCommand(struct cmdargs const *);
145static int AddCommand(struct cmdargs const *);
146static int DeleteCommand(struct cmdargs const *);
147static int NegotiateCommand(struct cmdargs const *);
148static int ClearCommand(struct cmdargs const *);
149static int RunListCommand(struct cmdargs const *);
150static int IfaceAddCommand(struct cmdargs const *);
151static int IfaceDeleteCommand(struct cmdargs const *);
152static int IfaceClearCommand(struct cmdargs const *);
149#ifndef NOALIAS
153#ifndef NOALIAS
150static int AliasCommand(struct cmdargs const *);
151static int AliasEnable(struct cmdargs const *);
152static int AliasOption(struct cmdargs const *);
153#endif
154
155static const char *
156showcx(struct cmdtab const *cmd)
157{
158 if (cmd->lauth & LOCAL_CX)

--- 222 unchanged lines hidden (view full) ---

381 int arg;
382
383 nargv[0] = strdup(oargv[0]);
384 for (arg = 1; arg < argc; arg++) {
385 nargv[arg] = strdup(oargv[arg]);
386 nargv[arg] = subst(nargv[arg], "HISADDR",
387 inet_ntoa(bundle->ncp.ipcp.peer_ip));
388 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
154static int AliasEnable(struct cmdargs const *);
155static int AliasOption(struct cmdargs const *);
156#endif
157
158static const char *
159showcx(struct cmdtab const *cmd)
160{
161 if (cmd->lauth & LOCAL_CX)

--- 222 unchanged lines hidden (view full) ---

384 int arg;
385
386 nargv[0] = strdup(oargv[0]);
387 for (arg = 1; arg < argc; arg++) {
388 nargv[arg] = strdup(oargv[arg]);
389 nargv[arg] = subst(nargv[arg], "HISADDR",
390 inet_ntoa(bundle->ncp.ipcp.peer_ip));
391 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
389 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->ifp.Name);
392 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->iface->name);
390 nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip));
391 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
392 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC",
393 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class,
394 bundle->ncp.mp.peer.enddisc.address,
395 bundle->ncp.mp.peer.enddisc.len));
396 nargv[arg] = subst(nargv[arg], "ENDDISC",
397 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,

--- 110 unchanged lines hidden (view full) ---

508}
509
510static int
511FgShellCommand(struct cmdargs const *arg)
512{
513 return ShellCommand(arg, 0);
514}
515
393 nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip));
394 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
395 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC",
396 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class,
397 bundle->ncp.mp.peer.enddisc.address,
398 bundle->ncp.mp.peer.enddisc.len));
399 nargv[arg] = subst(nargv[arg], "ENDDISC",
400 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,

--- 110 unchanged lines hidden (view full) ---

511}
512
513static int
514FgShellCommand(struct cmdargs const *arg)
515{
516 return ShellCommand(arg, 0);
517}
518
519#ifndef NOALIAS
520static struct cmdtab const AliasCommands[] =
521{
522 {"addr", NULL, alias_RedirectAddr, LOCAL_AUTH,
523 "static address translation", "alias addr [addr_local addr_alias]"},
524 {"deny_incoming", NULL, AliasOption, LOCAL_AUTH,
525 "stop incoming connections", "alias deny_incoming [yes|no]",
526 (const void *) PKT_ALIAS_DENY_INCOMING},
527 {"enable", NULL, AliasEnable, LOCAL_AUTH,
528 "enable IP aliasing", "alias enable [yes|no]"},
529 {"log", NULL, AliasOption, LOCAL_AUTH,
530 "log aliasing link creation", "alias log [yes|no]",
531 (const void *) PKT_ALIAS_LOG},
532 {"port", NULL, alias_RedirectPort, LOCAL_AUTH,
533 "port redirection", "alias port [proto addr_local:port_local port_alias]"},
534 {"same_ports", NULL, AliasOption, LOCAL_AUTH,
535 "try to leave port numbers unchanged", "alias same_ports [yes|no]",
536 (const void *) PKT_ALIAS_SAME_PORTS},
537 {"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
538 "alias unregistered (private) IP address space only",
539 "alias unregistered_only [yes|no]",
540 (const void *) PKT_ALIAS_UNREGISTERED_ONLY},
541 {"use_sockets", NULL, AliasOption, LOCAL_AUTH,
542 "allocate host sockets", "alias use_sockets [yes|no]",
543 (const void *) PKT_ALIAS_USE_SOCKETS},
544 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
545 "Display this message", "alias help|? [command]", AliasCommands},
546 {NULL, NULL, NULL},
547};
548#endif
549
550static struct cmdtab const AllowCommands[] = {
551 {"modes", "mode", AllowModes, LOCAL_AUTH,
552 "Only allow certain ppp modes", "allow modes mode..."},
553 {"users", "user", AllowUsers, LOCAL_AUTH,
554 "Only allow ppp access to certain users", "allow users logname..."},
555 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
556 "Display this message", "allow help|? [command]", AllowCommands},
557 {NULL, NULL, NULL},
558};
559
560static struct cmdtab const IfaceCommands[] =
561{
562 {"add", NULL, IfaceAddCommand, LOCAL_AUTH,
563 "Add iface address", "iface add addr[/bits| mask] peer", NULL},
564 {NULL, "add!", IfaceAddCommand, LOCAL_AUTH,
565 "Add or change an iface address", "iface add! addr[/bits| mask] peer",
566 (void *)1},
567 {"clear", NULL, IfaceClearCommand, LOCAL_AUTH,
568 "Clear iface address(es)", "iface clear"},
569 {"delete", "rm", IfaceDeleteCommand, LOCAL_AUTH,
570 "Delete iface address", "iface delete addr", NULL},
571 {NULL, "rm!", IfaceDeleteCommand, LOCAL_AUTH,
572 "Delete iface address", "iface delete addr", (void *)1},
573 {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH,
574 "Delete iface address", "iface delete addr", (void *)1},
575 {"show", NULL, iface_Show, LOCAL_AUTH,
576 "Show iface address(es)", "iface show"},
577 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
578 "Display this message", "alias help|? [command]", IfaceCommands},
579 {NULL, NULL, NULL},
580};
581
516static struct cmdtab const Commands[] = {
517 {"accept", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
518 "accept option request", "accept option .."},
519 {"add", NULL, AddCommand, LOCAL_AUTH,
520 "add route", "add dest mask gateway", NULL},
521 {NULL, "add!", AddCommand, LOCAL_AUTH,
522 "add or change route", "add! dest mask gateway", (void *)1},
523#ifndef NOALIAS
582static struct cmdtab const Commands[] = {
583 {"accept", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
584 "accept option request", "accept option .."},
585 {"add", NULL, AddCommand, LOCAL_AUTH,
586 "add route", "add dest mask gateway", NULL},
587 {NULL, "add!", AddCommand, LOCAL_AUTH,
588 "add or change route", "add! dest mask gateway", (void *)1},
589#ifndef NOALIAS
524 {"alias", NULL, AliasCommand, LOCAL_AUTH,
525 "alias control", "alias option [yes|no]"},
590 {"alias", NULL, RunListCommand, LOCAL_AUTH,
591 "alias control", "alias option [yes|no]", AliasCommands},
526#endif
592#endif
527 {"allow", "auth", AllowCommand, LOCAL_AUTH,
528 "Allow ppp access", "allow users|modes ...."},
593 {"allow", "auth", RunListCommand, LOCAL_AUTH,
594 "Allow ppp access", "allow users|modes ....", AllowCommands},
529 {"bg", "!bg", BgShellCommand, LOCAL_AUTH,
530 "Run a background command", "[!]bg command"},
531 {"clear", NULL, ClearCommand, LOCAL_AUTH | LOCAL_CX_OPT,
532 "Clear throughput statistics", "clear ipcp|modem [current|overall|peak]..."},
533 {"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
534 "Clone a link", "clone newname..."},
535 {"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
536 "Close an FSM", "close [lcp|ccp]"},

--- 6 unchanged lines hidden (view full) ---

543 {"dial", "call", DialCommand, LOCAL_AUTH | LOCAL_CX_OPT,
544 "Dial and login", "dial|call [remote]", NULL},
545 {"disable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
546 "Disable option", "disable option .."},
547 {"down", NULL, DownCommand, LOCAL_AUTH | LOCAL_CX_OPT,
548 "Generate a down event", "down"},
549 {"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
550 "Enable option", "enable option .."},
595 {"bg", "!bg", BgShellCommand, LOCAL_AUTH,
596 "Run a background command", "[!]bg command"},
597 {"clear", NULL, ClearCommand, LOCAL_AUTH | LOCAL_CX_OPT,
598 "Clear throughput statistics", "clear ipcp|modem [current|overall|peak]..."},
599 {"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
600 "Clone a link", "clone newname..."},
601 {"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
602 "Close an FSM", "close [lcp|ccp]"},

--- 6 unchanged lines hidden (view full) ---

609 {"dial", "call", DialCommand, LOCAL_AUTH | LOCAL_CX_OPT,
610 "Dial and login", "dial|call [remote]", NULL},
611 {"disable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
612 "Disable option", "disable option .."},
613 {"down", NULL, DownCommand, LOCAL_AUTH | LOCAL_CX_OPT,
614 "Generate a down event", "down"},
615 {"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
616 "Enable option", "enable option .."},
617 {"iface", "interface", RunListCommand, LOCAL_AUTH,
618 "interface control", "iface option ...", IfaceCommands},
551 {"link", "datalink", LinkCommand, LOCAL_AUTH,
552 "Link specific commands", "link name command ..."},
553 {"load", NULL, LoadCommand, LOCAL_AUTH | LOCAL_CX_OPT,
554 "Load settings", "load [remote]"},
555 {"open", NULL, OpenCommand, LOCAL_AUTH | LOCAL_CX_OPT,
556 "Open an FSM", "open! [lcp|ccp|ipcp]", (void *)1},
557 {"passwd", NULL, PasswdCommand, LOCAL_NO_AUTH,
558 "Password for manipulation", "passwd LocalPassword"},

--- 91 unchanged lines hidden (view full) ---

650 {"compress", NULL, sl_Show, LOCAL_AUTH,
651 "VJ compression stats", "show compress"},
652 {"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
653 "escape characters", "show escape"},
654 {"filter", NULL, filter_Show, LOCAL_AUTH,
655 "packet filters", "show filter [in|out|dial|alive]"},
656 {"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
657 "HDLC errors", "show hdlc"},
619 {"link", "datalink", LinkCommand, LOCAL_AUTH,
620 "Link specific commands", "link name command ..."},
621 {"load", NULL, LoadCommand, LOCAL_AUTH | LOCAL_CX_OPT,
622 "Load settings", "load [remote]"},
623 {"open", NULL, OpenCommand, LOCAL_AUTH | LOCAL_CX_OPT,
624 "Open an FSM", "open! [lcp|ccp|ipcp]", (void *)1},
625 {"passwd", NULL, PasswdCommand, LOCAL_NO_AUTH,
626 "Password for manipulation", "passwd LocalPassword"},

--- 91 unchanged lines hidden (view full) ---

718 {"compress", NULL, sl_Show, LOCAL_AUTH,
719 "VJ compression stats", "show compress"},
720 {"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
721 "escape characters", "show escape"},
722 {"filter", NULL, filter_Show, LOCAL_AUTH,
723 "packet filters", "show filter [in|out|dial|alive]"},
724 {"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
725 "HDLC errors", "show hdlc"},
726 {"iface", "interface", iface_Show, LOCAL_AUTH,
727 "Interface status", "show iface"},
658 {"ipcp", NULL, ipcp_Show, LOCAL_AUTH,
659 "IPCP status", "show ipcp"},
660 {"lcp", NULL, lcp_ReportStatus, LOCAL_AUTH | LOCAL_CX,
661 "LCP status", "show lcp"},
662 {"link", "datalink", datalink_Show, LOCAL_AUTH | LOCAL_CX,
663 "(high-level) link info", "show link"},
664 {"links", NULL, bundle_ShowLinks, LOCAL_AUTH,
665 "available link names", "show links"},

--- 529 unchanged lines hidden (view full) ---

1195}
1196
1197static int
1198SetInterfaceAddr(struct cmdargs const *arg)
1199{
1200 struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
1201 const char *hisaddr;
1202
728 {"ipcp", NULL, ipcp_Show, LOCAL_AUTH,
729 "IPCP status", "show ipcp"},
730 {"lcp", NULL, lcp_ReportStatus, LOCAL_AUTH | LOCAL_CX,
731 "LCP status", "show lcp"},
732 {"link", "datalink", datalink_Show, LOCAL_AUTH | LOCAL_CX,
733 "(high-level) link info", "show link"},
734 {"links", NULL, bundle_ShowLinks, LOCAL_AUTH,
735 "available link names", "show links"},

--- 529 unchanged lines hidden (view full) ---

1265}
1266
1267static int
1268SetInterfaceAddr(struct cmdargs const *arg)
1269{
1270 struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
1271 const char *hisaddr;
1272
1203 hisaddr = NULL;
1204 ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
1205 ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
1206
1207 if (arg->argc > arg->argn + 4)
1208 return -1;
1209
1273 if (arg->argc > arg->argn + 4)
1274 return -1;
1275
1276 hisaddr = NULL;
1277 ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
1278 ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
1210 ipcp->cfg.HaveTriggerAddress = 0;
1211 ipcp->cfg.netmask.s_addr = INADDR_ANY;
1212 iplist_reset(&ipcp->cfg.peer_list);
1213
1214 if (arg->argc > arg->argn) {
1215 if (!ParseAddr(ipcp, arg->argc - arg->argn, arg->argv + arg->argn,
1216 &ipcp->cfg.my_range.ipaddr, &ipcp->cfg.my_range.mask,
1217 &ipcp->cfg.my_range.width))

--- 5 unchanged lines hidden (view full) ---

1223 if (arg->argc > arg->argn+3) {
1224 ipcp->cfg.TriggerAddress = GetIpAddr(arg->argv[arg->argn+3]);
1225 ipcp->cfg.HaveTriggerAddress = 1;
1226 }
1227 }
1228 }
1229 }
1230
1279 ipcp->cfg.HaveTriggerAddress = 0;
1280 ipcp->cfg.netmask.s_addr = INADDR_ANY;
1281 iplist_reset(&ipcp->cfg.peer_list);
1282
1283 if (arg->argc > arg->argn) {
1284 if (!ParseAddr(ipcp, arg->argc - arg->argn, arg->argv + arg->argn,
1285 &ipcp->cfg.my_range.ipaddr, &ipcp->cfg.my_range.mask,
1286 &ipcp->cfg.my_range.width))

--- 5 unchanged lines hidden (view full) ---

1292 if (arg->argc > arg->argn+3) {
1293 ipcp->cfg.TriggerAddress = GetIpAddr(arg->argv[arg->argn+3]);
1294 ipcp->cfg.HaveTriggerAddress = 1;
1295 }
1296 }
1297 }
1298 }
1299
1231 /*
1232 * For backwards compatibility, 0.0.0.0 means any address.
1233 */
1300 /* 0.0.0.0 means any address (0 bits) */
1234 if (ipcp->cfg.my_range.ipaddr.s_addr == INADDR_ANY) {
1235 ipcp->cfg.my_range.mask.s_addr = INADDR_ANY;
1236 ipcp->cfg.my_range.width = 0;
1237 }
1238 ipcp->my_ip.s_addr = ipcp->cfg.my_range.ipaddr.s_addr;
1239
1301 if (ipcp->cfg.my_range.ipaddr.s_addr == INADDR_ANY) {
1302 ipcp->cfg.my_range.mask.s_addr = INADDR_ANY;
1303 ipcp->cfg.my_range.width = 0;
1304 }
1305 ipcp->my_ip.s_addr = ipcp->cfg.my_range.ipaddr.s_addr;
1306
1240 if (ipcp->cfg.peer_range.ipaddr.s_addr == INADDR_ANY) {
1241 ipcp->cfg.peer_range.mask.s_addr = INADDR_ANY;
1242 ipcp->cfg.peer_range.width = 0;
1243 }
1244
1245 if (hisaddr && !ipcp_UseHisaddr(arg->bundle, hisaddr,
1246 arg->bundle->phys_type.all & PHYS_AUTO))
1247 return 4;
1248
1249 return 0;
1250}
1251
1252static int

--- 459 unchanged lines hidden (view full) ---

1712 prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
1713 " syntax help.\n");
1714 else
1715 log_Printf(LogWARN, "set command must have arguments\n");
1716
1717 return 0;
1718}
1719
1307 if (hisaddr && !ipcp_UseHisaddr(arg->bundle, hisaddr,
1308 arg->bundle->phys_type.all & PHYS_AUTO))
1309 return 4;
1310
1311 return 0;
1312}
1313
1314static int

--- 459 unchanged lines hidden (view full) ---

1774 prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
1775 " syntax help.\n");
1776 else
1777 log_Printf(LogWARN, "set command must have arguments\n");
1778
1779 return 0;
1780}
1781
1720
1721static int
1722AddCommand(struct cmdargs const *arg)
1723{
1724 struct in_addr dest, gateway, netmask;
1725 int gw, addrs;
1726
1727 if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
1728 return -1;

--- 25 unchanged lines hidden (view full) ---

1754 dest = GetIpAddr(arg->argv[arg->argn]);
1755 netmask = GetIpAddr(arg->argv[arg->argn+1]);
1756 gw = 2;
1757 }
1758
1759 if (strcasecmp(arg->argv[arg->argn+gw], "HISADDR") == 0) {
1760 gateway = arg->bundle->ncp.ipcp.peer_ip;
1761 addrs |= ROUTE_GWHISADDR;
1782static int
1783AddCommand(struct cmdargs const *arg)
1784{
1785 struct in_addr dest, gateway, netmask;
1786 int gw, addrs;
1787
1788 if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
1789 return -1;

--- 25 unchanged lines hidden (view full) ---

1815 dest = GetIpAddr(arg->argv[arg->argn]);
1816 netmask = GetIpAddr(arg->argv[arg->argn+1]);
1817 gw = 2;
1818 }
1819
1820 if (strcasecmp(arg->argv[arg->argn+gw], "HISADDR") == 0) {
1821 gateway = arg->bundle->ncp.ipcp.peer_ip;
1822 addrs |= ROUTE_GWHISADDR;
1762 } else if (strcasecmp(arg->argv[arg->argn+gw], "INTERFACE") == 0)
1763 gateway.s_addr = INADDR_ANY;
1764 else
1823 } else
1765 gateway = GetIpAddr(arg->argv[arg->argn+gw]);
1766
1767 if (bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
1768 arg->cmd->args ? 1 : 0, (addrs & ROUTE_GWHISADDR) ? 1 : 0))
1769 route_Add(&arg->bundle->ncp.ipcp.route, addrs, dest, netmask, gateway);
1770
1771 return 0;
1772}

--- 30 unchanged lines hidden (view full) ---

1803 }
1804 } else
1805 return -1;
1806
1807 return 0;
1808}
1809
1810#ifndef NOALIAS
1824 gateway = GetIpAddr(arg->argv[arg->argn+gw]);
1825
1826 if (bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
1827 arg->cmd->args ? 1 : 0, (addrs & ROUTE_GWHISADDR) ? 1 : 0))
1828 route_Add(&arg->bundle->ncp.ipcp.route, addrs, dest, netmask, gateway);
1829
1830 return 0;
1831}

--- 30 unchanged lines hidden (view full) ---

1862 }
1863 } else
1864 return -1;
1865
1866 return 0;
1867}
1868
1869#ifndef NOALIAS
1811static struct cmdtab const AliasCommands[] =
1812{
1813 {"addr", NULL, alias_RedirectAddr, LOCAL_AUTH,
1814 "static address translation", "alias addr [addr_local addr_alias]"},
1815 {"deny_incoming", NULL, AliasOption, LOCAL_AUTH,
1816 "stop incoming connections", "alias deny_incoming [yes|no]",
1817 (const void *) PKT_ALIAS_DENY_INCOMING},
1818 {"enable", NULL, AliasEnable, LOCAL_AUTH,
1819 "enable IP aliasing", "alias enable [yes|no]"},
1820 {"log", NULL, AliasOption, LOCAL_AUTH,
1821 "log aliasing link creation", "alias log [yes|no]",
1822 (const void *) PKT_ALIAS_LOG},
1823 {"port", NULL, alias_RedirectPort, LOCAL_AUTH,
1824 "port redirection", "alias port [proto addr_local:port_local port_alias]"},
1825 {"same_ports", NULL, AliasOption, LOCAL_AUTH,
1826 "try to leave port numbers unchanged", "alias same_ports [yes|no]",
1827 (const void *) PKT_ALIAS_SAME_PORTS},
1828 {"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
1829 "alias unregistered (private) IP address space only",
1830 "alias unregistered_only [yes|no]",
1831 (const void *) PKT_ALIAS_UNREGISTERED_ONLY},
1832 {"use_sockets", NULL, AliasOption, LOCAL_AUTH,
1833 "allocate host sockets", "alias use_sockets [yes|no]",
1834 (const void *) PKT_ALIAS_USE_SOCKETS},
1835 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
1836 "Display this message", "alias help|? [command]", AliasCommands},
1837 {NULL, NULL, NULL},
1838};
1839
1840
1841static int
1870static int
1842AliasCommand(struct cmdargs const *arg)
1843{
1844 if (arg->argc > arg->argn)
1845 FindExec(arg->bundle, AliasCommands, arg->argc, arg->argn, arg->argv,
1846 arg->prompt, arg->cx);
1847 else if (arg->prompt)
1848 prompt_Printf(arg->prompt, "Use `alias help' to get a list or `alias help"
1849 " <option>' for syntax help.\n");
1850 else
1851 log_Printf(LogWARN, "alias command must have arguments\n");
1852
1853 return 0;
1854}
1855
1856static int
1857AliasEnable(struct cmdargs const *arg)
1858{
1859 if (arg->argc == arg->argn+1) {
1860 if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
1861 arg->bundle->AliasEnabled = 1;
1862 return 0;
1863 } else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
1864 arg->bundle->AliasEnabled = 0;
1871AliasEnable(struct cmdargs const *arg)
1872{
1873 if (arg->argc == arg->argn+1) {
1874 if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
1875 arg->bundle->AliasEnabled = 1;
1876 return 0;
1877 } else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
1878 arg->bundle->AliasEnabled = 0;
1879 arg->bundle->cfg.opt &= ~OPT_IFACEALIAS;
1880 /* Don't iface_Clear() - there may be manually configured addresses */
1865 return 0;
1866 }
1867 }
1868
1869 return -1;
1870}
1871
1872

--- 16 unchanged lines hidden (view full) ---

1889 }
1890 log_Printf(LogWARN, "alias not enabled\n");
1891 }
1892 }
1893 return -1;
1894}
1895#endif /* #ifndef NOALIAS */
1896
1881 return 0;
1882 }
1883 }
1884
1885 return -1;
1886}
1887
1888

--- 16 unchanged lines hidden (view full) ---

1905 }
1906 log_Printf(LogWARN, "alias not enabled\n");
1907 }
1908 }
1909 return -1;
1910}
1911#endif /* #ifndef NOALIAS */
1912
1897static struct cmdtab const AllowCommands[] = {
1898 {"modes", "mode", AllowModes, LOCAL_AUTH,
1899 "Only allow certain ppp modes", "allow modes mode..."},
1900 {"users", "user", AllowUsers, LOCAL_AUTH,
1901 "Allow users access to ppp", "allow users logname..."},
1902 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
1903 "Display this message", "allow help|? [command]", AllowCommands},
1904 {NULL, NULL, NULL},
1905};
1906
1907static int
1913static int
1908AllowCommand(struct cmdargs const *arg)
1909{
1910 /* arg->bundle may be NULL (see system_IsValid()) ! */
1911 if (arg->argc > arg->argn)
1912 FindExec(arg->bundle, AllowCommands, arg->argc, arg->argn, arg->argv,
1913 arg->prompt, arg->cx);
1914 else if (arg->prompt)
1915 prompt_Printf(arg->prompt, "Use `allow ?' to get a list or `allow ? <cmd>'"
1916 " for syntax help.\n");
1917 else
1918 log_Printf(LogWARN, "allow command must have arguments\n");
1919
1920 return 0;
1921}
1922
1923static int
1924LinkCommand(struct cmdargs const *arg)
1925{
1926 if (arg->argc > arg->argn+1) {
1927 char namelist[LINE_LEN];
1928 struct datalink *cx;
1929 char *name;
1930 int result = 0;
1931

--- 110 unchanged lines hidden (view full) ---

2042 if (add)
2043 arg->bundle->cfg.opt |= bit;
2044 else
2045 arg->bundle->cfg.opt &= ~bit;
2046 return 0;
2047}
2048
2049static int
1914LinkCommand(struct cmdargs const *arg)
1915{
1916 if (arg->argc > arg->argn+1) {
1917 char namelist[LINE_LEN];
1918 struct datalink *cx;
1919 char *name;
1920 int result = 0;
1921

--- 110 unchanged lines hidden (view full) ---

2032 if (add)
2033 arg->bundle->cfg.opt |= bit;
2034 else
2035 arg->bundle->cfg.opt &= ~bit;
2036 return 0;
2037}
2038
2039static int
2040IfaceAliasOptSet(struct cmdargs const *arg)
2041{
2042 unsigned save = arg->bundle->cfg.opt;
2043 int result = OptSet(arg);
2044
2045 if (result == 0)
2046 if (Enabled(arg->bundle, OPT_IFACEALIAS) && !arg->bundle->AliasEnabled) {
2047 arg->bundle->cfg.opt = save;
2048 log_Printf(LogWARN, "Cannot enable iface-alias without IP aliasing\n");
2049 result = 2;
2050 }
2051
2052 return result;
2053}
2054
2055static int
2050NegotiateSet(struct cmdargs const *arg)
2051{
2052 long param = (long)arg->cmd->args;
2053 struct link *l = command_ChooseLink(arg); /* LOCAL_CX_OPT uses this */
2054 struct datalink *cx = arg->cx; /* LOCAL_CX uses this */
2055 const char *cmd;
2056 unsigned keep; /* Keep these bits */
2057 unsigned add; /* Add these bits */

--- 75 unchanged lines hidden (view full) ---

2133 {"proxy", NULL, OptSet, LOCAL_AUTH, "Create proxy ARP entry",
2134 "disable|enable", (const void *)OPT_PROXY},
2135 {"sroutes", NULL, OptSet, LOCAL_AUTH, "Use sticky routes",
2136 "disable|enable", (const void *)OPT_SROUTES},
2137 {"throughput", NULL, OptSet, LOCAL_AUTH, "Rolling throughput",
2138 "disable|enable", (const void *)OPT_THROUGHPUT},
2139 {"utmp", NULL, OptSet, LOCAL_AUTH, "Log connections in utmp",
2140 "disable|enable", (const void *)OPT_UTMP},
2056NegotiateSet(struct cmdargs const *arg)
2057{
2058 long param = (long)arg->cmd->args;
2059 struct link *l = command_ChooseLink(arg); /* LOCAL_CX_OPT uses this */
2060 struct datalink *cx = arg->cx; /* LOCAL_CX uses this */
2061 const char *cmd;
2062 unsigned keep; /* Keep these bits */
2063 unsigned add; /* Add these bits */

--- 75 unchanged lines hidden (view full) ---

2139 {"proxy", NULL, OptSet, LOCAL_AUTH, "Create proxy ARP entry",
2140 "disable|enable", (const void *)OPT_PROXY},
2141 {"sroutes", NULL, OptSet, LOCAL_AUTH, "Use sticky routes",
2142 "disable|enable", (const void *)OPT_SROUTES},
2143 {"throughput", NULL, OptSet, LOCAL_AUTH, "Rolling throughput",
2144 "disable|enable", (const void *)OPT_THROUGHPUT},
2145 {"utmp", NULL, OptSet, LOCAL_AUTH, "Log connections in utmp",
2146 "disable|enable", (const void *)OPT_UTMP},
2147 {"iface-alias", NULL, IfaceAliasOptSet, LOCAL_AUTH,
2148 "maintain interface addresses", "disable|enable",
2149 (const void *)OPT_IFACEALIAS},
2141
2150
2142#define OPT_MAX 7 /* accept/deny allowed below and not above */
2151#define OPT_MAX 8 /* accept/deny allowed below and not above */
2143
2144 {"acfcomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2145 "Address & Control field compression", "accept|deny|disable|enable",
2146 (const void *)NEG_ACFCOMP},
2147 {"chap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2148 "Challenge Handshake Authentication Protocol", "accept|deny|disable|enable",
2149 (const void *)NEG_CHAP},
2150 {"deflate", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,

--- 102 unchanged lines hidden (view full) ---

2253 else
2254 return -1;
2255 } else
2256 clear_type = THROUGHPUT_ALL;
2257
2258 throughput_clear(t, clear_type, arg->prompt);
2259 return 0;
2260}
2152
2153 {"acfcomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2154 "Address & Control field compression", "accept|deny|disable|enable",
2155 (const void *)NEG_ACFCOMP},
2156 {"chap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2157 "Challenge Handshake Authentication Protocol", "accept|deny|disable|enable",
2158 (const void *)NEG_CHAP},
2159 {"deflate", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,

--- 102 unchanged lines hidden (view full) ---

2262 else
2263 return -1;
2264 } else
2265 clear_type = THROUGHPUT_ALL;
2266
2267 throughput_clear(t, clear_type, arg->prompt);
2268 return 0;
2269}
2270
2271static int
2272RunListCommand(struct cmdargs const *arg)
2273{
2274 const char *cmd = arg->argc ? arg->argv[arg->argc - 1] : "???";
2275
2276 if (arg->argc > arg->argn)
2277 FindExec(arg->bundle, arg->cmd->args, arg->argc, arg->argn, arg->argv,
2278 arg->prompt, arg->cx);
2279 else if (arg->prompt)
2280 prompt_Printf(arg->prompt, "Use `%s help' to get a list or `%s help"
2281 " <option>' for syntax help.\n", cmd, cmd);
2282 else
2283 log_Printf(LogWARN, "%s command must have arguments\n", cmd);
2284
2285 return 0;
2286}
2287
2288static int
2289IfaceAddCommand(struct cmdargs const *arg)
2290{
2291 int bits, n, how;
2292 struct in_addr ifa, mask, brd;
2293
2294 if (arg->argc == arg->argn + 2) {
2295 if (!ParseAddr(NULL, 1, arg->argv + arg->argn, &ifa, &mask, &bits))
2296 return -1;
2297 n = 1;
2298 } else if (arg->argc == arg->argn + 3) {
2299 if (!ParseAddr(NULL, 1, arg->argv + arg->argn, &ifa, NULL, NULL))
2300 return -1;
2301 if (!ParseAddr(NULL, 1, arg->argv + arg->argn + 1, &mask, NULL, NULL))
2302 return -1;
2303 n = 2;
2304 } else
2305 return -1;
2306
2307 if (!ParseAddr(NULL, 1, arg->argv + arg->argn + n, &brd, NULL, NULL))
2308 return -1;
2309
2310 how = IFACE_ADD_LAST;
2311 if (arg->cmd->args)
2312 how |= IFACE_FORCE_ADD;
2313
2314 return !iface_inAdd(arg->bundle->iface, ifa, mask, brd, how);
2315}
2316
2317static int
2318IfaceDeleteCommand(struct cmdargs const *arg)
2319{
2320 struct in_addr ifa;
2321 int ok;
2322
2323 if (arg->argc != arg->argn + 1)
2324 return -1;
2325
2326 if (!ParseAddr(NULL, 1, arg->argv + arg->argn, &ifa, NULL, NULL))
2327 return -1;
2328
2329 if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED &&
2330 arg->bundle->ncp.ipcp.my_ip.s_addr == ifa.s_addr) {
2331 log_Printf(LogWARN, "%s: Cannot remove active interface address\n",
2332 inet_ntoa(ifa));
2333 return 1;
2334 }
2335
2336 ok = iface_inDelete(arg->bundle->iface, ifa);
2337 if (!ok) {
2338 if (arg->cmd->args)
2339 ok = 1;
2340 else if (arg->prompt)
2341 prompt_Printf(arg->prompt, "%s: No such address\n", inet_ntoa(ifa));
2342 else
2343 log_Printf(LogWARN, "%s: No such address\n", inet_ntoa(ifa));
2344 }
2345
2346 return !ok;
2347}
2348
2349static int
2350IfaceClearCommand(struct cmdargs const *arg)
2351{
2352 int how;
2353
2354 if (arg->argc != arg->argn)
2355 return -1;
2356
2357 how = arg->bundle->ncp.ipcp.fsm.state == ST_OPENED ?
2358 IFACE_CLEAR_ALIASES : IFACE_CLEAR_ALL;
2359 iface_Clear(arg->bundle->iface, how);
2360
2361 return 0;
2362}