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.
20 #define RCSID "$Id: options.c,v 1.64 1999/08/13 06:46:16 paulus Exp $"
33 #include <sys/types.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
39 #include <pcap-int.h> /* XXX: To get struct pcap */
43 #include "pathnames.h"
44 #include "patchlevel.h"
52 #include <net/ppp-comp.h>
54 #if defined(ultrix) || defined(NeXT)
55 char *strdup __P((char *));
58 static const char rcsid[] = RCSID;
61 * Option variables and default values.
64 int dflag = 0; /* Tell libpcap we want debugging */
66 int debug = 0; /* Debug flag */
67 int kdebugflag = 0; /* Tell kernel to print debug messages */
68 int default_device = 1; /* Using /dev/tty or equivalent */
69 char devnam[MAXPATHLEN]; /* Device name */
70 int crtscts = 0; /* Use hardware flow control */
71 bool modem = 1; /* Use modem control lines */
72 int inspeed = 0; /* Input/Output speed requested */
73 u_int32_t netmask = 0; /* IP netmask to set on interface */
74 bool lockflag = 0; /* Create lock file to lock the serial dev */
75 bool nodetach = 0; /* Don't detach from controlling tty */
76 bool updetach = 0; /* Detach once link is up */
77 char *initializer = NULL; /* Script to initialize physical link */
78 char *connector = NULL; /* Script to establish physical link */
79 char *disconnector = NULL; /* Script to disestablish physical link */
80 char *welcomer = NULL; /* Script to run after phys link estab. */
81 char *ptycommand = NULL; /* Command to run on other side of pty */
82 int maxconnect = 0; /* Maximum connect time */
83 char user[MAXNAMELEN]; /* Username for PAP */
84 char passwd[MAXSECRETLEN]; /* Password for PAP */
85 bool persist = 0; /* Reopen link after it goes down */
86 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
87 bool demand = 0; /* do dial-on-demand */
88 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
89 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
90 int holdoff = 30; /* # seconds to pause before reconnecting */
91 bool notty = 0; /* Stdin/out is not a tty */
92 char *record_file = NULL; /* File to record chars sent/received */
94 bool sync_serial = 0; /* Device is synchronous serial device */
95 int log_to_fd = 1; /* send log messages to this fd too */
96 int maxfail = 10; /* max # of unsuccessful connection attempts */
97 char linkname[MAXPATHLEN]; /* logical name for link */
99 extern option_t auth_options[];
100 extern struct stat devstat;
101 extern int prepass; /* Doing pre-pass to find device name */
103 struct option_info initializer_info;
104 struct option_info connector_info;
105 struct option_info disconnector_info;
106 struct option_info welcomer_info;
107 struct option_info devnam_info;
108 struct option_info ptycommand_info;
111 struct bpf_program pass_filter;/* Filter program for packets to pass */
112 struct bpf_program active_filter; /* Filter program for link-active pkts */
113 pcap_t pc; /* Fake struct pcap so we can compile expr */
116 char *current_option; /* the name of the option being parsed */
117 int privileged_option; /* set iff the current option came from root */
118 char *option_source; /* string saying where the option came from */
119 bool log_to_file; /* log_to_fd is a file opened by us */
124 static int setdevname __P((char *));
125 static int setipaddr __P((char *));
126 static int setspeed __P((char *));
127 static int noopt __P((char **));
128 static int setdomain __P((char **));
129 static int setnetmask __P((char **));
130 static int setxonxoff __P((char **));
131 static int readfile __P((char **));
132 static int callfile __P((char **));
133 static int showversion __P((char **));
134 static int showhelp __P((char **));
135 static void usage __P((void));
136 static int setlogfile __P((char **));
139 static int setpassfilter __P((char **));
140 static int setactivefilter __P((char **));
144 static option_t *find_option __P((char *name));
145 static int process_option __P((option_t *, char **));
146 static int n_arguments __P((option_t *));
147 static int number_option __P((char *, u_int32_t *, int));
152 option_t general_options[] = {
153 { "debug", o_int, &debug,
154 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
155 { "-d", o_int, &debug,
156 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
157 { "kdebug", o_int, &kdebugflag,
158 "Set kernel driver debug level" },
159 { "nodetach", o_bool, &nodetach,
160 "Don't detach from controlling tty", 1 },
161 { "-detach", o_bool, &nodetach,
162 "Don't detach from controlling tty", 1 },
163 { "updetach", o_bool, &updetach,
164 "Detach from controlling tty once link is up", 1 },
165 { "holdoff", o_int, &holdoff,
166 "Set time in seconds before retrying connection" },
167 { "idle", o_int, &idle_time_limit,
168 "Set time in seconds before disconnecting idle link" },
169 { "lock", o_bool, &lockflag,
170 "Lock serial device with UUCP-style lock file", 1 },
171 { "-all", o_special_noarg, noopt,
172 "Don't request/allow any LCP or IPCP options (useless)" },
173 { "init", o_string, &initializer,
174 "A program to initialize the device",
175 OPT_A2INFO | OPT_PRIVFIX, &initializer_info },
176 { "connect", o_string, &connector,
177 "A program to set up a connection",
178 OPT_A2INFO | OPT_PRIVFIX, &connector_info },
179 { "disconnect", o_string, &disconnector,
180 "Program to disconnect serial device",
181 OPT_A2INFO | OPT_PRIVFIX, &disconnector_info },
182 { "welcome", o_string, &welcomer,
183 "Script to welcome client",
184 OPT_A2INFO | OPT_PRIVFIX, &welcomer_info },
185 { "pty", o_string, &ptycommand,
186 "Script to run on pseudo-tty master side",
187 OPT_A2INFO | OPT_PRIVFIX | OPT_DEVNAM, &ptycommand_info },
188 { "notty", o_bool, ¬ty,
189 "Input/output is not a tty", OPT_DEVNAM | 1 },
190 { "record", o_string, &record_file,
191 "Record characters sent/received to file" },
192 { "maxconnect", o_int, &maxconnect,
193 "Set connection time limit", OPT_LLIMIT|OPT_NOINCR|OPT_ZEROINF },
194 { "crtscts", o_int, &crtscts,
195 "Set hardware (RTS/CTS) flow control", OPT_NOARG|OPT_VAL(1) },
196 { "nocrtscts", o_int, &crtscts,
197 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
198 { "-crtscts", o_int, &crtscts,
199 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
200 { "cdtrcts", o_int, &crtscts,
201 "Set alternate hardware (DTR/CTS) flow control", OPT_NOARG|OPT_VAL(2) },
202 { "nocdtrcts", o_int, &crtscts,
203 "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
204 { "xonxoff", o_special_noarg, setxonxoff,
205 "Set software (XON/XOFF) flow control" },
206 { "domain", o_special, setdomain,
207 "Add given domain name to hostname" },
208 { "mtu", o_int, &lcp_allowoptions[0].mru,
209 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
210 { "netmask", o_special, setnetmask,
212 { "modem", o_bool, &modem,
213 "Use modem control lines", 1 },
214 { "local", o_bool, &modem,
215 "Don't use modem control lines" },
216 { "file", o_special, readfile,
217 "Take options from a file", OPT_PREPASS },
218 { "call", o_special, callfile,
219 "Take options from a privileged file", OPT_PREPASS },
220 { "persist", o_bool, &persist,
221 "Keep on reopening connection after close", 1 },
222 { "nopersist", o_bool, &persist,
223 "Turn off persist option" },
224 { "demand", o_bool, &demand,
225 "Dial on demand", OPT_INITONLY | 1, &persist },
226 { "--version", o_special_noarg, showversion,
227 "Show version number" },
228 { "--help", o_special_noarg, showhelp,
229 "Show brief listing of options" },
230 { "-h", o_special_noarg, showhelp,
231 "Show brief listing of options" },
232 { "sync", o_bool, &sync_serial,
233 "Use synchronous HDLC serial encoding", 1 },
234 { "logfd", o_int, &log_to_fd,
235 "Send log messages to this file descriptor" },
236 { "logfile", o_special, setlogfile,
237 "Append log messages to this file" },
238 { "nolog", o_int, &log_to_fd,
239 "Don't send log messages to any file",
240 OPT_NOARG | OPT_VAL(-1) },
241 { "nologfd", o_int, &log_to_fd,
242 "Don't send log messages to any file descriptor",
243 OPT_NOARG | OPT_VAL(-1) },
244 { "linkname", o_string, linkname,
245 "Set logical name for link",
246 OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
247 { "maxfail", o_int, &maxfail,
248 "Maximum number of unsuccessful connection attempts to allow" },
251 { "pdebug", o_int, &dflag,
252 "libpcap debugging" },
253 { "pass-filter", 1, setpassfilter,
254 "set filter for packets to pass" },
255 { "active-filter", 1, setactivefilter,
256 "set filter for active pkts" },
262 #ifndef IMPLEMENTATION
263 #define IMPLEMENTATION ""
266 static char *usage_string = "\
267 pppd version %s.%d%s\n\
268 Usage: %s [ options ], where options are:\n\
269 <device> Communicate over the named device\n\
270 <speed> Set the baud rate to <speed>\n\
271 <loc>:<rem> Set the local and/or remote interface IP\n\
272 addresses. Either one may be omitted.\n\
273 asyncmap <n> Set the desired async map to hex <n>\n\
274 auth Require authentication from peer\n\
275 connect <p> Invoke shell command <p> to set up the serial line\n\
276 crtscts Use hardware RTS/CTS flow control\n\
277 defaultroute Add default route through interface\n\
278 file <f> Take options from file <f>\n\
279 modem Use modem control lines\n\
280 mru <n> Set MRU value to <n> for negotiation\n\
281 See pppd(8) for more options.\n\
285 * parse_args - parse a string of arguments from the command line.
286 * If prepass is true, we are scanning for the device name and only
287 * processing a few options, so error messages are suppressed.
290 parse_args(argc, argv)
298 privileged_option = privileged;
299 option_source = "command line";
305 * First see if it's an option in the new option list.
307 opt = find_option(arg);
309 int n = n_arguments(opt);
311 option_error("too few parameters for option %s", arg);
314 current_option = arg;
315 if (!process_option(opt, argv))
323 * Maybe a tty name, speed or IP address?
325 if ((ret = setdevname(arg)) == 0
326 && (ret = setspeed(arg)) == 0
327 && (ret = setipaddr(arg)) == 0) {
328 option_error("unrecognized option '%s'", arg);
332 if (ret < 0) /* error */
340 * scan_args - scan the command line arguments to get the tty name,
341 * if specified. Also checks whether the notty or pty option was given.
344 scan_args(argc, argv)
351 privileged_option = privileged;
356 if (strcmp(arg, "notty") == 0 || strcmp(arg, "pty") == 0)
359 /* Skip options and their arguments */
360 opt = find_option(arg);
362 int n = n_arguments(opt);
368 /* Check if it's a tty name and copy it if so */
369 (void) setdevname(arg, 1);
375 * options_from_file - Read a string of options from a file,
376 * and interpret them.
379 options_from_file(filename, must_exist, check_prot, priv)
386 int i, newline, ret, err;
391 char args[MAXARGS][MAXWORDLEN];
392 char cmd[MAXWORDLEN];
396 f = fopen(filename, "r");
401 if (!must_exist && err == ENOENT)
404 option_error("Can't open options file %s: %m", filename);
408 oldpriv = privileged_option;
409 privileged_option = priv;
410 oldsource = option_source;
411 option_source = strdup(filename);
412 if (option_source == NULL)
413 option_source = "file";
415 while (getword(f, cmd, &newline, filename)) {
417 * First see if it's a command.
419 opt = find_option(cmd);
421 int n = n_arguments(opt);
422 for (i = 0; i < n; ++i) {
423 if (!getword(f, args[i], &newline, filename)) {
425 "In file %s: too few parameters for option '%s'",
431 current_option = cmd;
432 if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
433 option_error("the %s option may not be used in the %s file",
437 if (!process_option(opt, argv))
443 * Maybe a tty name, speed or IP address?
445 if ((i = setdevname(cmd)) == 0
446 && (i = setspeed(cmd)) == 0
447 && (i = setipaddr(cmd)) == 0) {
448 option_error("In file %s: unrecognized option '%s'",
452 if (i < 0) /* error */
459 privileged_option = oldpriv;
460 option_source = oldsource;
465 * options_from_user - See if the use has a ~/.ppprc file,
466 * and if so, interpret options from it.
471 char *user, *path, *file;
476 pw = getpwuid(getuid());
477 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
479 file = _PATH_USEROPT;
480 pl = strlen(user) + strlen(file) + 2;
483 novm("init file name");
484 slprintf(path, pl, "%s/%s", user, file);
485 ret = options_from_file(path, 0, 1, privileged);
491 * options_for_tty - See if an options file exists for the serial
492 * device, and if so, interpret options from it.
497 char *dev, *path, *p;
502 if (strncmp(dev, "/dev/", 5) == 0)
504 if (dev[0] == 0 || strcmp(dev, "tty") == 0)
505 return 1; /* don't look for /etc/ppp/options.tty */
506 pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
509 novm("tty init file name");
510 slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
511 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
512 for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
515 ret = options_from_file(path, 0, 0, 1);
521 * options_from_list - process a string of options in a wordlist.
524 options_from_list(w, priv)
532 privileged_option = priv;
533 option_source = "secrets file";
537 * First see if it's a command.
539 opt = find_option(w->word);
541 int n = n_arguments(opt);
542 struct wordlist *w0 = w;
543 for (i = 0; i < n; ++i) {
547 "In secrets file: too few parameters for option '%s'",
553 current_option = w0->word;
554 if (!process_option(opt, argv))
560 * Maybe a tty name, speed or IP address?
562 if ((i = setdevname(w->word)) == 0
563 && (i = setspeed(w->word)) == 0
564 && (i = setipaddr(w->word)) == 0) {
565 option_error("In secrets file: unrecognized option '%s'",
569 if (i < 0) /* error */
579 * find_option - scan the option lists for the various protocols
580 * looking for an entry with the given name.
581 * This could be optimized by using a hash table.
590 for (opt = general_options; opt->name != NULL; ++opt)
591 if (strcmp(name, opt->name) == 0)
593 for (opt = auth_options; opt->name != NULL; ++opt)
594 if (strcmp(name, opt->name) == 0)
596 for (i = 0; protocols[i] != NULL; ++i)
597 if ((opt = protocols[i]->options) != NULL)
598 for (; opt->name != NULL; ++opt)
599 if (strcmp(name, opt->name) == 0)
605 * process_option - process one new-style option.
608 process_option(opt, argv)
615 int (*parser) __P((char **));
617 if ((opt->flags & OPT_PREPASS) == 0 && prepass)
619 if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
620 option_error("it's too late to use the %s option", opt->name);
623 if ((opt->flags & OPT_PRIV) && !privileged_option) {
624 option_error("using the %s option requires root privilege", opt->name);
627 if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
628 option_error("%s option is disabled", opt->name);
631 if ((opt->flags & OPT_PRIVFIX) && !privileged_option) {
632 struct option_info *ip = (struct option_info *) opt->addr2;
633 if (ip && ip->priv) {
634 option_error("%s option cannot be overridden", opt->name);
641 v = opt->flags & OPT_VALUE;
642 *(bool *)(opt->addr) = v;
643 if (opt->addr2 && (opt->flags & OPT_A2COPY))
644 *(bool *)(opt->addr2) = v;
649 if ((opt->flags & OPT_NOARG) == 0) {
650 if (!int_option(*argv, &iv))
652 if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
653 || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
654 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
655 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
656 switch (opt->flags & OPT_LIMITS) {
658 option_error("%s value must be%s >= %d",
659 opt->name, zok, opt->lower_limit);
662 option_error("%s value must be%s <= %d",
663 opt->name, zok, opt->upper_limit);
666 option_error("%s value must be%s between %d and %d",
667 opt->name, opt->lower_limit, opt->upper_limit);
673 a = opt->flags & OPT_VALUE;
675 a -= 256; /* sign extend */
677 if (opt->flags & OPT_INC)
678 iv += *(int *)(opt->addr);
679 if ((opt->flags & OPT_NOINCR) && !privileged_option) {
680 int oldv = *(int *)(opt->addr);
681 if ((opt->flags & OPT_ZEROINF) ?
682 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
683 option_error("%s value cannot be increased", opt->name);
687 *(int *)(opt->addr) = iv;
688 if (opt->addr2 && (opt->flags & OPT_A2COPY))
689 *(int *)(opt->addr2) = iv;
693 if (opt->flags & OPT_NOARG) {
694 v = opt->flags & OPT_VALUE;
695 } else if (!number_option(*argv, &v, 16))
697 if (opt->flags & OPT_OR)
698 v |= *(u_int32_t *)(opt->addr);
699 *(u_int32_t *)(opt->addr) = v;
700 if (opt->addr2 && (opt->flags & OPT_A2COPY))
701 *(u_int32_t *)(opt->addr2) = v;
705 if (opt->flags & OPT_STATIC) {
706 strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
710 novm("option argument");
711 *(char **)(opt->addr) = sv;
715 case o_special_noarg:
717 parser = (int (*) __P((char **))) opt->addr;
718 if (!(*parser)(argv))
724 if (opt->flags & OPT_A2INFO) {
725 struct option_info *ip = (struct option_info *) opt->addr2;
726 ip->priv = privileged_option;
727 ip->source = option_source;
728 } else if ((opt->flags & (OPT_A2COPY|OPT_ENABLE)) == 0)
729 *(bool *)(opt->addr2) = 1;
736 * n_arguments - tell how many arguments an option takes
742 return (opt->type == o_bool || opt->type == o_special_noarg
743 || (opt->flags & OPT_NOARG))? 0: 1;
747 * usage - print out a message telling how to use the program.
752 if (phase == PHASE_INITIALIZE)
753 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
758 * showhelp - print out usage message and exit.
764 if (phase == PHASE_INITIALIZE) {
772 * showversion - print out the version number and exit.
778 if (phase == PHASE_INITIALIZE) {
779 fprintf(stderr, "pppd version %s.%d%s\n",
780 VERSION, PATCHLEVEL, IMPLEMENTATION);
787 * option_error - print a message about an error in an option.
788 * The message is logged, and also sent to
789 * stderr if phase == PHASE_INITIALIZE.
792 option_error __V((char *fmt, ...))
802 fmt = va_arg(args, char *);
808 vslprintf(buf, sizeof(buf), fmt, args);
810 if (phase == PHASE_INITIALIZE)
811 fprintf(stderr, "%s: %s\n", progname, buf);
812 syslog(LOG_ERR, "%s", buf);
817 * readable - check if a file is readable by the real user.
830 if (fstat(fd, &sbuf) != 0)
832 if (sbuf.st_uid == uid)
833 return sbuf.st_mode & S_IRUSR;
834 if (sbuf.st_gid == getgid())
835 return sbuf.st_mode & S_IRGRP;
836 for (i = 0; i < ngroups; ++i)
837 if (sbuf.st_gid == groups[i])
838 return sbuf.st_mode & S_IRGRP;
839 return sbuf.st_mode & S_IROTH;
844 * Read a word from a file.
845 * Words are delimited by white-space or by quotes (" or ').
846 * Quotes, white-space and \ may be escaped with \.
847 * \<newline> is ignored.
850 getword(f, word, newlinep, filename)
858 int value, digit, got, n;
860 #define isoctal(c) ((c) >= '0' && (c) < '8')
868 * First skip white-space and comments.
876 * A newline means the end of a comment; backslash-newline
877 * is ignored. Note that we cannot have escape && comment.
889 * Ignore characters other than newline in a comment.
895 * If this character is escaped, we have a word start.
901 * If this is the escape character, look at the next character.
909 * If this is the start of a comment, ignore the rest of the line.
917 * A non-whitespace character is the start of a word.
924 * Save the delimiter for quoted strings.
926 if (!escape && (c == '"' || c == '\'')) {
933 * Process characters until the end of the word.
938 * This character is escaped: backslash-newline is ignored,
939 * various other characters indicate particular values
940 * as for C backslash-escapes.
975 * \ddd octal sequence
978 for (n = 0; n < 3 && isoctal(c); ++n) {
979 value = (value << 3) + (c & 07);
988 * \x<hex_string> sequence
992 for (n = 0; n < 2 && isxdigit(c); ++n) {
993 digit = toupper(c) - '0';
995 digit += '0' + 10 - 'A';
996 value = (value << 4) + digit;
1004 * Otherwise the character stands for itself.
1011 * Store the resulting character for the escape sequence.
1013 if (len < MAXWORDLEN-1)
1024 * Not escaped: see if we've reached the end of the word.
1030 if (isspace(c) || c == '#') {
1037 * Backslash starts an escape sequence.
1046 * An ordinary character: store it in the word and get another.
1048 if (len < MAXWORDLEN-1)
1056 * End of the word: check for errors.
1062 option_error("Error reading %s: %m", filename);
1066 * If len is zero, then we didn't find a word before the
1074 * Warn if the word was too long, and append a terminating null.
1076 if (len >= MAXWORDLEN) {
1077 option_error("warning: word in file %s too long (%.20s...)",
1079 len = MAXWORDLEN - 1;
1090 * number_option - parse an unsigned numeric parameter for an option.
1093 number_option(str, valp, base)
1100 *valp = strtoul(str, &ptr, base);
1102 option_error("invalid numeric parameter '%s' for %s option",
1103 str, current_option);
1111 * int_option - like number_option, but valp is int *,
1112 * the base is assumed to be 0, and *valp is not changed
1113 * if there is an error.
1116 int_option(str, valp)
1122 if (!number_option(str, &v, 0))
1130 * The following procedures parse options.
1134 * readfile - take commands from a file.
1140 return options_from_file(*argv, 1, 1, privileged_option);
1144 * callfile - take commands from /etc/ppp/peers/<name>.
1145 * Name may not contain /../, start with / or ../, or end in /..
1151 char *fname, *arg, *p;
1156 if (arg[0] == '/' || arg[0] == 0)
1159 for (p = arg; *p != 0; ) {
1160 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1164 while (*p != '/' && *p != 0)
1171 option_error("call option value may not contain .. or start with /");
1175 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1176 if ((fname = (char *) malloc(l)) == NULL)
1177 novm("call file name");
1178 slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1180 ok = options_from_file(fname, 1, 1, 1);
1188 * setpdebug - Set libpcap debugging level.
1194 return int_option(*argv, &dflag);
1198 * setpassfilter - Set the pass filter for packets
1204 pc.linktype = DLT_PPP;
1205 pc.snapshot = PPP_HDRLEN;
1207 if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1209 option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1214 * setactivefilter - Set the active filter for packets
1217 setactivefilter(argv)
1220 pc.linktype = DLT_PPP;
1221 pc.snapshot = PPP_HDRLEN;
1223 if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1225 option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1231 * noopt - Disable all options.
1237 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1238 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1239 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1240 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1246 * setdomain - Set domain name to append to hostname
1252 if (!privileged_option) {
1253 option_error("using the domain option requires root privilege");
1256 gethostname(hostname, MAXNAMELEN);
1259 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1260 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1262 hostname[MAXNAMELEN-1] = 0;
1268 * setspeed - Set the speed.
1277 spd = strtol(arg, &ptr, 0);
1278 if (ptr == arg || *ptr != 0 || spd == 0)
1286 * setdevname - Set the device name.
1292 struct stat statbuf;
1293 char dev[MAXPATHLEN];
1298 if (strncmp("/dev/", cp, 5) != 0) {
1299 strlcpy(dev, "/dev/", sizeof(dev));
1300 strlcat(dev, cp, sizeof(dev));
1305 * Check if there is a character device by this name.
1307 if (stat(cp, &statbuf) < 0) {
1308 if (errno == ENOENT)
1310 option_error("Couldn't stat %s: %m", cp);
1313 if (!S_ISCHR(statbuf.st_mode)) {
1314 option_error("%s is not a character device", cp);
1318 if (phase != PHASE_INITIALIZE) {
1319 option_error("device name cannot be changed after initialization");
1321 } else if (devnam_fixed) {
1322 option_error("per-tty options file may not specify device name");
1326 if (devnam_info.priv && !privileged_option) {
1327 option_error("device name cannot be overridden");
1331 strlcpy(devnam, cp, sizeof(devnam));
1334 devnam_info.priv = privileged_option;
1335 devnam_info.source = option_source;
1342 * setipaddr - Set the IP address
1350 u_int32_t local, remote;
1351 ipcp_options *wo = &ipcp_wantoptions[0];
1354 * IP address pair separated by ":".
1356 if ((colon = strchr(arg, ':')) == NULL)
1362 * If colon first character, then no local addr.
1366 if ((local = inet_addr(arg)) == -1) {
1367 if ((hp = gethostbyname(arg)) == NULL) {
1368 option_error("unknown host: %s", arg);
1371 local = *(u_int32_t *)hp->h_addr;
1374 if (bad_ip_adrs(local)) {
1375 option_error("bad local IP address %s", ip_ntoa(local));
1379 wo->ouraddr = local;
1384 * If colon last character, then no remote addr.
1386 if (*++colon != '\0') {
1387 if ((remote = inet_addr(colon)) == -1) {
1388 if ((hp = gethostbyname(colon)) == NULL) {
1389 option_error("unknown host: %s", colon);
1392 remote = *(u_int32_t *)hp->h_addr;
1393 if (remote_name[0] == 0)
1394 strlcpy(remote_name, colon, sizeof(remote_name));
1397 if (bad_ip_adrs(remote)) {
1398 option_error("bad remote IP address %s", ip_ntoa(remote));
1402 wo->hisaddr = remote;
1410 * setnetmask - set the netmask to be used on the interface.
1421 * Unfortunately, if we use inet_addr, we can't tell whether
1422 * a result of all 1s is an error or a valid 255.255.255.255.
1428 b = strtoul(p, &endp, 0);
1431 if (b < 0 || b > 255) {
1433 /* accept e.g. 0xffffff00 */
1439 mask |= b << (n * 8);
1441 if (*p != '.' || n == 0)
1448 if (*p != 0 || (netmask & ~mask) != 0) {
1449 option_error("invalid netmask value '%s'", *argv);
1461 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1462 lcp_wantoptions[0].neg_asyncmap = 1;
1474 if (!privileged_option)
1476 fd = open(*argv, O_WRONLY | O_APPEND);
1478 if (!privileged_option)
1482 option_error("Can't open log file %s: %m", *argv);
1485 if (log_to_file && log_to_fd >= 0)