2 * options.c - handles option processing for PPP.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 static char rcsid[] = "$Id: options.c,v 1.20 1995/06/12 11:22:51 paulus Exp $";
34 #include <sys/types.h>
36 #include <netinet/in.h>
39 #include "pathnames.h"
40 #include "patchlevel.h"
48 #include <net/ppp-comp.h>
53 #if defined(ultrix) || defined(NeXT)
54 char *strdup __P((char *));
58 #define GIDSET_TYPE gid_t
62 * Option variables and default values.
64 int debug = 0; /* Debug flag */
65 int kdebugflag = 0; /* Tell kernel to print debug messages */
66 int default_device = 1; /* Using /dev/tty or equivalent */
67 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
68 int crtscts = 0; /* Use hardware flow control */
69 int modem = 1; /* Use modem control lines */
70 int inspeed = 0; /* Input/Output speed requested */
71 u_int32_t netmask = 0; /* IP netmask to set on interface */
72 int lockflag = 0; /* Create lock file to lock the serial dev */
73 int nodetach = 0; /* Don't detach from controlling tty */
74 char *connector = NULL; /* Script to establish physical link */
75 char *disconnector = NULL; /* Script to disestablish physical link */
76 char user[MAXNAMELEN]; /* Username for PAP */
77 char passwd[MAXSECRETLEN]; /* Password for PAP */
78 int auth_required = 0; /* Peer is required to authenticate */
79 int defaultroute = 0; /* assign default route through interface */
80 int proxyarp = 0; /* Set up proxy ARP entry for peer */
81 int persist = 0; /* Reopen link after it goes down */
82 int uselogin = 0; /* Use /etc/passwd for checking PAP */
83 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
84 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
85 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
86 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
87 int usehostname = 0; /* Use hostname for our_name */
88 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
89 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
90 int cryptpap; /* Passwords in pap-secrets are encrypted */
93 int idle_time_limit = 0;
94 static int setidle __P((char **));
100 static int setdebug __P((void));
101 static int setkdebug __P((char **));
102 static int setpassive __P((void));
103 static int setsilent __P((void));
104 static int noopt __P((void));
105 static int setnovj __P((void));
106 static int setnovjccomp __P((void));
107 static int setvjslots __P((char **));
108 static int reqpap __P((void));
109 static int nopap __P((void));
110 static int setupapfile __P((char **));
111 static int nochap __P((void));
112 static int reqchap __P((void));
113 static int setspeed __P((char *));
114 static int noaccomp __P((void));
115 static int noasyncmap __P((void));
116 static int noipaddr __P((void));
117 static int nomagicnumber __P((void));
118 static int setasyncmap __P((char **));
119 static int setescape __P((char **));
120 static int setmru __P((char **));
121 static int setmtu __P((char **));
122 static int nomru __P((void));
123 static int nopcomp __P((void));
124 static int setconnector __P((char **));
125 static int setdisconnector __P((char **));
126 static int setdomain __P((char **));
127 static int setnetmask __P((char **));
128 static int setcrtscts __P((void));
129 static int setnocrtscts __P((void));
130 static int setxonxoff __P((void));
131 static int setnodetach __P((void));
132 static int setmodem __P((void));
133 static int setlocal __P((void));
134 static int setlock __P((void));
135 static int setname __P((char **));
136 static int setuser __P((char **));
137 static int setremote __P((char **));
138 static int setauth __P((void));
139 static int readfile __P((char **));
140 static int setdefaultroute __P((void));
141 static int setproxyarp __P((void));
142 static int setpersist __P((void));
143 static int setdologin __P((void));
144 static int setusehostname __P((void));
145 static int setnoipdflt __P((void));
146 static int setlcptimeout __P((char **));
147 static int setlcpterm __P((char **));
148 static int setlcpconf __P((char **));
149 static int setlcpfails __P((char **));
150 static int setipcptimeout __P((char **));
151 static int setipcpterm __P((char **));
152 static int setipcpconf __P((char **));
153 static int setipcpfails __P((char **));
154 static int setpaptimeout __P((char **));
155 static int setpapreqs __P((char **));
156 static int setchaptimeout __P((char **));
157 static int setchapchal __P((char **));
158 static int setchapintv __P((char **));
159 static int setipcpaccl __P((void));
160 static int setipcpaccr __P((void));
161 static int setlcpechointv __P((char **));
162 static int setlcpechofails __P((char **));
163 static int setbsdcomp __P((char **));
164 static int setnobsdcomp __P((void));
165 static int setipparam __P((char **));
166 static int setpapcrypt __P((void));
168 static int number_option __P((char *, long *, int));
169 static int readable __P((int fd));
181 {"-all", 0, noopt}, /* Don't request/allow any options */
182 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
183 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
184 {"-as", 1, setasyncmap}, /* set the desired async map */
185 {"-d", 0, setdebug}, /* Increase debugging level */
186 {"-detach", 0, setnodetach}, /* don't fork */
187 {"-ip", 0, noipaddr}, /* Disable IP address negotiation */
188 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
189 {"-mru", 0, nomru}, /* Disable mru negotiation */
190 {"-p", 0, setpassive}, /* Set passive mode */
191 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
192 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
193 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
194 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
195 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
196 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
197 {"-vj", 0, setnovj}, /* disable VJ compression */
198 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
199 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
200 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
201 {"escape", 1, setescape}, /* set chars to escape on transmission */
202 {"connect", 1, setconnector}, /* A program to set up a connection */
203 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
204 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
205 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
206 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
207 {"debug", 0, setdebug}, /* Increase debugging level */
208 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
209 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
210 {"mru", 1, setmru}, /* Set MRU value for negotiation */
211 {"mtu", 1, setmtu}, /* Set our MTU */
212 {"netmask", 1, setnetmask}, /* set netmask */
213 {"passive", 0, setpassive}, /* Set passive mode */
214 {"silent", 0, setsilent}, /* Set silent mode */
215 {"modem", 0, setmodem}, /* Use modem control lines */
216 {"local", 0, setlocal}, /* Don't use modem control lines */
217 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
218 {"name", 1, setname}, /* Set local name for authentication */
219 {"user", 1, setuser}, /* Set username for PAP auth with peer */
220 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
221 {"remotename", 1, setremote}, /* Set remote name for authentication */
222 {"auth", 0, setauth}, /* Require authentication from peer */
223 {"file", 1, readfile}, /* Take options from a file */
224 {"defaultroute", 0, setdefaultroute}, /* Add default route */
225 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
226 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
227 {"login", 0, setdologin}, /* Use system password database for UPAP */
228 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
229 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
230 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
231 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
232 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
233 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
234 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
235 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
236 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
237 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
238 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
239 {"pap-restart", 1, setpaptimeout}, /* Set timeout for UPAP */
240 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
241 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
242 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
243 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
244 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
245 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
246 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
247 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
248 {"ipparam", 1, setipparam}, /* set ip script parameter */
249 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
251 {"idle-disconnect", 1, setidle}, /* seconds for disconnect of idle IP */
257 #ifndef IMPLEMENTATION
258 #define IMPLEMENTATION ""
261 static char *usage_string = "\
262 pppd version %s patch level %d%s\n\
263 Usage: %s [ arguments ], where arguments are:\n\
264 <device> Communicate over the named device\n\
265 <speed> Set the baud rate to <speed>\n\
266 <loc>:<rem> Set the local and/or remote interface IP\n\
267 addresses. Either one may be omitted.\n\
268 asyncmap <n> Set the desired async map to hex <n>\n\
269 auth Require authentication from peer\n\
270 connect <p> Invoke shell command <p> to set up the serial line\n\
271 crtscts Use hardware RTS/CTS flow control\n\
272 defaultroute Add default route through interface\n\
273 file <f> Take options from file <f>\n\
274 modem Use modem control lines\n\
275 mru <n> Set MRU value to <n> for negotiation\n\
276 netmask <n> Set interface netmask to <n>\n\
277 See pppd(8) for more options.\n\
282 * parse_args - parse a string of arguments, from the command
283 * line or from a file.
286 parse_args(argc, argv)
299 * First see if it's a command.
301 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
302 if (!strcmp(arg, cmdp->cmd_name))
305 if (cmdp->cmd_name != NULL) {
306 if (argc < cmdp->num_args) {
307 fprintf(stderr, "Too few parameters for command %s\n", arg);
310 if (!(*cmdp->cmd_func)(argv))
312 argc -= cmdp->num_args;
313 argv += cmdp->num_args;
317 * Maybe a tty name, speed or IP address?
319 if ((ret = setdevname(arg)) == 0
320 && (ret = setspeed(arg)) == 0
321 && (ret = setipaddr(arg)) == 0) {
322 fprintf(stderr, "%s: unrecognized command\n", arg);
326 if (ret < 0) /* error */
334 * usage - print out a message telling how to use the program.
339 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
344 * options_from_file - Read a string of options from a file,
345 * and interpret them.
348 options_from_file(filename, must_exist, check_prot)
357 char args[MAXARGS][MAXWORDLEN];
358 char cmd[MAXWORDLEN];
360 if ((f = fopen(filename, "r")) == NULL) {
361 if (!must_exist && errno == ENOENT)
366 if (check_prot && !readable(fileno(f))) {
367 fprintf(stderr, "%s: access denied\n", filename);
372 while (getword(f, cmd, &newline, filename)) {
374 * First see if it's a command.
376 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
377 if (!strcmp(cmd, cmdp->cmd_name))
380 if (cmdp->cmd_name != NULL) {
381 for (i = 0; i < cmdp->num_args; ++i) {
382 if (!getword(f, args[i], &newline, filename)) {
384 "In file %s: too few parameters for command %s\n",
391 if (!(*cmdp->cmd_func)(argv)) {
398 * Maybe a tty name, speed or IP address?
400 if ((ret = setdevname(cmd)) == 0
401 && (ret = setspeed(cmd)) == 0
402 && (ret = setipaddr(cmd)) == 0) {
403 fprintf(stderr, "In file %s: unrecognized command %s\n",
408 if (ret < 0) /* error */
416 * options_from_user - See if the use has a ~/.ppprc file,
417 * and if so, interpret options from it.
422 char *user, *path, *file;
426 pw = getpwuid(getuid());
427 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
429 file = _PATH_USEROPT;
430 path = malloc(strlen(user) + strlen(file) + 2);
432 novm("init file name");
436 ret = options_from_file(path, 0, 1);
442 * options_for_tty - See if an options file exists for the serial
443 * device, and if so, interpret options from it.
451 dev = strrchr(devnam, '/');
456 if (strcmp(dev, "tty") == 0)
457 return 1; /* don't look for /etc/ppp/options.tty */
458 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
460 novm("tty init file name");
461 strcpy(path, _PATH_TTYOPT);
463 ret = options_from_file(path, 0, 0);
469 * readable - check if a file is readable by the real user.
478 GIDSET_TYPE groups[NGROUPS_MAX];
483 if (fstat(fd, &sbuf) != 0)
485 if (sbuf.st_uid == uid)
486 return sbuf.st_mode & S_IRUSR;
487 if (sbuf.st_gid == getgid())
488 return sbuf.st_mode & S_IRGRP;
489 ngroups = getgroups(NGROUPS_MAX, groups);
490 for (i = 0; i < ngroups; ++i)
491 if (sbuf.st_gid == groups[i])
492 return sbuf.st_mode & S_IRGRP;
493 return sbuf.st_mode & S_IROTH;
497 * Read a word from a file.
498 * Words are delimited by white-space or by quotes (", or ').
499 * Quotes, white-space and \ may be escaped with \.
500 * \<newline> is ignored.
504 getword(f, word, newlinep, filename)
512 int value, digit, got, n;
514 #define isoctal(c) ((c) >= '0' && (c) < '8')
522 * First skip white-space and comments.
530 * A newline means the end of a comment; backslash-newline
531 * is ignored. Note that we cannot have escape && comment.
543 * Ignore characters other than newline in a comment.
549 * If this character is escaped, we have a word start.
555 * If this is the escape character, look at the next character.
563 * If this is the start of a comment, ignore the rest of the line.
571 * A non-whitespace character is the start of a word.
578 * Save the delimiter for quoted strings.
580 if (!escape && (c == '"' || c == '\'')) {
587 * Process characters until the end of the word.
592 * This character is escaped: backslash-newline is ignored,
593 * various other characters indicate particular values
594 * as for C backslash-escapes.
629 * \ddd octal sequence
632 for (n = 0; n < 3 && isoctal(c); ++n) {
633 value = (value << 3) + (c & 07);
642 * \x<hex_string> sequence
646 for (n = 0; n < 2 && isxdigit(c); ++n) {
647 digit = toupper(c) - '0';
649 digit += '0' + 10 - 'A';
650 value = (value << 4) + digit;
658 * Otherwise the character stands for itself.
665 * Store the resulting character for the escape sequence.
667 if (len < MAXWORDLEN-1)
678 * Not escaped: see if we've reached the end of the word.
684 if (isspace(c) || c == '#') {
691 * Backslash starts an escape sequence.
700 * An ordinary character: store it in the word and get another.
702 if (len < MAXWORDLEN-1)
710 * End of the word: check for errors.
720 * If len is zero, then we didn't find a word before the
728 * Warn if the word was too long, and append a terminating null.
730 if (len >= MAXWORDLEN) {
731 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
732 progname, filename, word);
733 len = MAXWORDLEN - 1;
744 * number_option - parse a numeric parameter for an option
747 number_option(str, valp, base)
754 *valp = strtol(str, &ptr, base);
756 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
764 * int_option - like number_option, but valp is int *,
765 * the base is assumed to be 0, and *valp is not changed
766 * if there is an error.
769 int_option(str, valp)
775 if (!number_option(str, &v, 0))
783 * The following procedures execute commands.
787 * readfile - take commands from a file.
793 return options_from_file(*argv, 1, 1);
797 * setdebug - Set debug (command line argument).
807 * setkdebug - Set kernel debugging level.
813 return int_option(*argv, &kdebugflag);
817 * noopt - Disable all options.
822 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
823 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
824 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
825 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
830 * noaccomp - Disable Address/Control field compression negotiation.
835 lcp_wantoptions[0].neg_accompression = 0;
836 lcp_allowoptions[0].neg_accompression = 0;
842 * noasyncmap - Disable async map negotiation.
847 lcp_wantoptions[0].neg_asyncmap = 0;
848 lcp_allowoptions[0].neg_asyncmap = 0;
854 * noipaddr - Disable IP address negotiation.
859 ipcp_wantoptions[0].neg_addr = 0;
860 ipcp_allowoptions[0].neg_addr = 0;
866 * nomagicnumber - Disable magic number negotiation.
871 lcp_wantoptions[0].neg_magicnumber = 0;
872 lcp_allowoptions[0].neg_magicnumber = 0;
878 * nomru - Disable mru negotiation.
883 lcp_wantoptions[0].neg_mru = 0;
884 lcp_allowoptions[0].neg_mru = 0;
890 * setmru - Set MRU for negotiation.
898 if (!number_option(*argv, &mru, 0))
900 lcp_wantoptions[0].mru = mru;
901 lcp_wantoptions[0].neg_mru = 1;
907 * setmru - Set the largest MTU we'll use.
915 if (!number_option(*argv, &mtu, 0))
917 if (mtu < MINMRU || mtu > MAXMRU) {
918 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
919 (mtu < MINMRU? "small": "large"));
922 lcp_allowoptions[0].mru = mtu;
928 * nopcomp - Disable Protocol field compression negotiation.
933 lcp_wantoptions[0].neg_pcompression = 0;
934 lcp_allowoptions[0].neg_pcompression = 0;
940 * setpassive - Set passive mode (don't give up if we time out sending
941 * LCP configure-requests).
946 lcp_wantoptions[0].passive = 1;
952 * setsilent - Set silent mode (don't start sending LCP configure-requests
953 * until we get one from the peer).
958 lcp_wantoptions[0].silent = 1;
964 * nopap - Disable PAP authentication with peer.
969 lcp_allowoptions[0].neg_upap = 0;
975 * reqpap - Require PAP authentication from peer.
980 lcp_wantoptions[0].neg_upap = 1;
987 * setupapfile - specifies UPAP info for authenticating with peer.
996 lcp_allowoptions[0].neg_upap = 1;
998 /* open user info file */
999 if ((ufile = fopen(*argv, "r")) == NULL) {
1000 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1003 if (!readable(fileno(ufile))) {
1004 fprintf(stderr, "%s: access denied\n", *argv);
1007 check_access(ufile, *argv);
1010 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1011 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1012 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1017 /* get rid of newlines */
1019 if (l > 0 && user[l-1] == '\n')
1022 if (l > 0 && passwd[l-1] == '\n')
1030 * nochap - Disable CHAP authentication with peer.
1035 lcp_allowoptions[0].neg_chap = 0;
1041 * reqchap - Require CHAP authentication from peer.
1046 lcp_wantoptions[0].neg_chap = 1;
1053 * setnovj - disable vj compression
1058 ipcp_wantoptions[0].neg_vj = 0;
1059 ipcp_allowoptions[0].neg_vj = 0;
1065 * setnovjccomp - disable VJ connection-ID compression
1070 ipcp_wantoptions[0].cflag = 0;
1071 ipcp_allowoptions[0].cflag = 0;
1077 * setvjslots - set maximum number of connection slots for VJ compression
1085 if (!int_option(*argv, &value))
1087 if (value < 2 || value > 16) {
1088 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1091 ipcp_wantoptions [0].maxslotindex =
1092 ipcp_allowoptions[0].maxslotindex = value - 1;
1098 * setconnector - Set a program to connect to a serial line
1104 connector = strdup(*argv);
1105 if (connector == NULL)
1106 novm("connector string");
1112 * setdisconnector - Set a program to disconnect from the serial line
1115 setdisconnector(argv)
1118 disconnector = strdup(*argv);
1119 if (disconnector == NULL)
1120 novm("disconnector string");
1127 * setdomain - Set domain name to append to hostname
1133 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1134 hostname[MAXNAMELEN-1] = 0;
1140 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1148 if (!number_option(*argv, &asyncmap, 16))
1150 lcp_wantoptions[0].asyncmap |= asyncmap;
1151 lcp_wantoptions[0].neg_asyncmap = 1;
1157 * setescape - add chars to the set we escape on transmission.
1169 n = strtol(p, &endp, 16);
1171 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1175 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1176 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1179 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1180 while (*p == ',' || *p == ' ')
1188 * setspeed - Set the speed.
1197 spd = strtol(arg, &ptr, 0);
1198 if (ptr == arg || *ptr != 0 || spd == 0)
1206 * setdevname - Set the device name.
1212 struct stat statbuf;
1213 char *tty, *ttyname();
1214 char dev[MAXPATHLEN];
1216 if (strncmp("/dev/", cp, 5) != 0) {
1217 strcpy(dev, "/dev/");
1218 strncat(dev, cp, MAXPATHLEN - 5);
1219 dev[MAXPATHLEN-1] = 0;
1224 * Check if there is a device by this name.
1226 if (stat(cp, &statbuf) < 0) {
1227 if (errno == ENOENT)
1229 syslog(LOG_ERR, cp);
1233 (void) strncpy(devnam, cp, MAXPATHLEN);
1234 devnam[MAXPATHLEN-1] = 0;
1235 default_device = FALSE;
1242 * setipaddr - Set the IP address
1250 u_int32_t local, remote;
1251 ipcp_options *wo = &ipcp_wantoptions[0];
1254 * IP address pair separated by ":".
1256 if ((colon = strchr(arg, ':')) == NULL)
1260 * If colon first character, then no local addr.
1264 if ((local = inet_addr(arg)) == -1) {
1265 if ((hp = gethostbyname(arg)) == NULL) {
1266 fprintf(stderr, "unknown host: %s\n", arg);
1269 local = *(u_int32_t *)hp->h_addr;
1270 if (our_name[0] == 0) {
1271 strncpy(our_name, arg, MAXNAMELEN);
1272 our_name[MAXNAMELEN-1] = 0;
1276 if (bad_ip_adrs(local)) {
1277 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1281 wo->ouraddr = local;
1286 * If colon last character, then no remote addr.
1288 if (*++colon != '\0') {
1289 if ((remote = inet_addr(colon)) == -1) {
1290 if ((hp = gethostbyname(colon)) == NULL) {
1291 fprintf(stderr, "unknown host: %s\n", colon);
1294 remote = *(u_int32_t *)hp->h_addr;
1295 if (remote_name[0] == 0) {
1296 strncpy(remote_name, colon, MAXNAMELEN);
1297 remote_name[MAXNAMELEN-1] = 0;
1301 if (bad_ip_adrs(remote)) {
1302 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1306 wo->hisaddr = remote;
1314 * setnoipdflt - disable setipdefault()
1319 disable_defaultip = 1;
1325 * setipcpaccl - accept peer's idea of our address
1330 ipcp_wantoptions[0].accept_local = 1;
1336 * setipcpaccr - accept peer's idea of its address
1341 ipcp_wantoptions[0].accept_remote = 1;
1347 * setipdefault - default our local IP address based on our hostname.
1354 ipcp_options *wo = &ipcp_wantoptions[0];
1357 * If local IP address already given, don't bother.
1359 if (wo->ouraddr != 0 || disable_defaultip)
1363 * Look up our hostname (possibly with domain name appended)
1364 * and take the first IP address as our local IP address.
1365 * If there isn't an IP address for our hostname, too bad.
1367 wo->accept_local = 1; /* don't insist on this default value */
1368 if ((hp = gethostbyname(hostname)) == NULL)
1370 local = *(u_int32_t *)hp->h_addr;
1371 if (local != 0 && !bad_ip_adrs(local))
1372 wo->ouraddr = local;
1377 * setnetmask - set the netmask to be used on the interface.
1385 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1386 fprintf(stderr, "Invalid netmask %s\n", *argv);
1411 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1412 lcp_wantoptions[0].neg_asyncmap = 1;
1457 if (our_name[0] == 0) {
1458 strncpy(our_name, argv[0], MAXNAMELEN);
1459 our_name[MAXNAMELEN-1] = 0;
1468 strncpy(user, argv[0], MAXNAMELEN);
1469 user[MAXNAMELEN-1] = 0;
1477 strncpy(remote_name, argv[0], MAXNAMELEN);
1478 remote_name[MAXNAMELEN-1] = 0;
1492 ipcp_wantoptions[0].default_route = 1;
1499 ipcp_wantoptions[0].proxy_arp = 1;
1518 * Functions to set the echo interval for modem-less monitors
1522 setlcpechointv(argv)
1525 return int_option(*argv, &lcp_echo_interval);
1529 setlcpechofails(argv)
1532 return int_option(*argv, &lcp_echo_fails);
1536 * Functions to set timeouts, max transmits, etc.
1542 return int_option(*argv, &lcp_fsm[0].timeouttime);
1549 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1556 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1563 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1567 setipcptimeout(argv)
1570 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1577 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1584 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1591 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1598 return int_option(*argv, &upap[0].us_timeouttime);
1605 return int_option(*argv, &upap[0].us_maxtransmits);
1609 setchaptimeout(argv)
1612 return int_option(*argv, &chap[0].timeouttime);
1619 return int_option(*argv, &chap[0].max_transmits);
1626 return int_option(*argv, &chap[0].chal_interval);
1637 abits = rbits = strtol(str, &endp, 0);
1638 if (endp != str && *endp == ',') {
1640 abits = strtol(str, &endp, 0);
1642 if (*endp != 0 || endp == str) {
1643 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1647 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1648 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1649 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1650 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1654 ccp_wantoptions[0].bsd_compress = 1;
1655 ccp_wantoptions[0].bsd_bits = rbits;
1657 ccp_wantoptions[0].bsd_compress = 0;
1659 ccp_allowoptions[0].bsd_compress = 1;
1660 ccp_allowoptions[0].bsd_bits = abits;
1662 ccp_allowoptions[0].bsd_compress = 0;
1669 ccp_wantoptions[0].bsd_compress = 0;
1670 ccp_allowoptions[0].bsd_compress = 0;
1678 ipparam = strdup(*argv);
1679 if (ipparam == NULL)
1680 novm("ipparam string");
1693 static int setidle (argv)
1696 return int_option(*argv, &idle_time_limit);