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.75 2000/06/30 04:54:21 paulus Exp $"
33 #include <sys/types.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
42 #include <pcap-int.h> /* XXX: To get struct pcap */
46 #include "pathnames.h"
47 #include "patchlevel.h"
55 #include <net/ppp-comp.h>
57 #if defined(ultrix) || defined(NeXT)
58 char *strdup __P((char *));
61 static const char rcsid[] = RCSID;
64 * Option variables and default values.
67 int dflag = 0; /* Tell libpcap we want debugging */
69 int debug = 0; /* Debug flag */
70 int kdebugflag = 0; /* Tell kernel to print debug messages */
71 int default_device = 1; /* Using /dev/tty or equivalent */
72 char devnam[MAXPATHLEN]; /* Device name */
73 u_int32_t netmask = 0; /* IP netmask to set on interface */
74 bool nodetach = 0; /* Don't detach from controlling tty */
75 bool updetach = 0; /* Detach once link is up */
76 int maxconnect = 0; /* Maximum connect time */
77 char user[MAXNAMELEN]; /* Username for PAP */
78 char passwd[MAXSECRETLEN]; /* Password for PAP */
79 bool persist = 0; /* Reopen link after it goes down */
80 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
81 bool demand = 0; /* do dial-on-demand */
82 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
83 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
84 int holdoff = 30; /* # seconds to pause before reconnecting */
85 bool holdoff_specified; /* true if a holdoff value has been given */
86 int log_to_fd = 1; /* send log messages to this fd too */
87 int maxfail = 10; /* max # of unsuccessful connection attempts */
88 char linkname[MAXPATHLEN]; /* logical name for link */
89 bool tune_kernel; /* may alter kernel settings */
90 int connect_delay = 1000; /* wait this many ms after connect script */
91 int req_unit = -1; /* requested interface unit */
92 bool multilink = 0; /* Enable multilink operation */
93 char *bundle_name = NULL; /* bundle name for multilink */
95 extern option_t auth_options[];
96 extern struct stat devstat;
98 struct option_info initializer_info;
99 struct option_info connect_script_info;
100 struct option_info disconnect_script_info;
101 struct option_info welcomer_info;
102 struct option_info devnam_info;
103 struct option_info ptycommand_info;
106 struct bpf_program pass_filter;/* Filter program for packets to pass */
107 struct bpf_program active_filter; /* Filter program for link-active pkts */
108 pcap_t pc; /* Fake struct pcap so we can compile expr */
111 char *current_option; /* the name of the option being parsed */
112 int privileged_option; /* set iff the current option came from root */
113 char *option_source; /* string saying where the option came from */
114 bool log_to_file; /* log_to_fd is a file opened by us */
115 bool log_to_specific_fd; /* log_to_fd was specified by user option */
116 bool no_override; /* don't override previously-set options */
121 static int setdevname __P((char *));
122 static int setipaddr __P((char *));
123 static int setspeed __P((char *));
124 static int noopt __P((char **));
125 static int setdomain __P((char **));
126 static int setnetmask __P((char **));
127 static int readfile __P((char **));
128 static int callfile __P((char **));
129 static int showversion __P((char **));
130 static int showhelp __P((char **));
131 static void usage __P((void));
132 static int setlogfile __P((char **));
134 static int loadplugin __P((char **));
138 static int setpassfilter __P((char **));
139 static int setactivefilter __P((char **));
142 static option_t *find_option __P((char *name));
143 static int process_option __P((option_t *, char **));
144 static int n_arguments __P((option_t *));
145 static int number_option __P((char *, u_int32_t *, int));
148 * Structure to store extra lists of options.
152 struct option_list *next;
155 static struct option_list *extra_options = NULL;
160 option_t general_options[] = {
161 { "debug", o_int, &debug,
162 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
163 { "-d", o_int, &debug,
164 "Increase debugging level", OPT_INC|OPT_NOARG|1 },
165 { "kdebug", o_int, &kdebugflag,
166 "Set kernel driver debug level" },
167 { "nodetach", o_bool, &nodetach,
168 "Don't detach from controlling tty", 1 },
169 { "-detach", o_bool, &nodetach,
170 "Don't detach from controlling tty", 1 },
171 { "updetach", o_bool, &updetach,
172 "Detach from controlling tty once link is up", 1 },
173 { "holdoff", o_int, &holdoff,
174 "Set time in seconds before retrying connection" },
175 { "idle", o_int, &idle_time_limit,
176 "Set time in seconds before disconnecting idle link" },
177 { "-all", o_special_noarg, (void *)noopt,
178 "Don't request/allow any LCP or IPCP options (useless)" },
179 { "maxconnect", o_int, &maxconnect,
180 "Set connection time limit", OPT_LLIMIT|OPT_NOINCR|OPT_ZEROINF },
181 { "domain", o_special, (void *)setdomain,
182 "Add given domain name to hostname" },
183 { "mtu", o_int, &lcp_allowoptions[0].mru,
184 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
185 { "netmask", o_special, (void *)setnetmask,
187 { "file", o_special, (void *)readfile,
188 "Take options from a file", OPT_PREPASS },
189 { "call", o_special, (void *)callfile,
190 "Take options from a privileged file", OPT_PREPASS },
191 { "persist", o_bool, &persist,
192 "Keep on reopening connection after close", 1 },
193 { "nopersist", o_bool, &persist,
194 "Turn off persist option" },
195 { "demand", o_bool, &demand,
196 "Dial on demand", OPT_INITONLY | 1, &persist },
197 { "--version", o_special_noarg, (void *)showversion,
198 "Show version number" },
199 { "--help", o_special_noarg, (void *)showhelp,
200 "Show brief listing of options" },
201 { "-h", o_special_noarg, (void *)showhelp,
202 "Show brief listing of options" },
203 { "logfd", o_int, &log_to_fd,
204 "Send log messages to this file descriptor",
205 0, &log_to_specific_fd },
206 { "logfile", o_special, (void *)setlogfile,
207 "Append log messages to this file" },
208 { "nolog", o_int, &log_to_fd,
209 "Don't send log messages to any file",
210 OPT_NOARG | OPT_VAL(-1) },
211 { "nologfd", o_int, &log_to_fd,
212 "Don't send log messages to any file descriptor",
213 OPT_NOARG | OPT_VAL(-1) },
214 { "linkname", o_string, linkname,
215 "Set logical name for link",
216 OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
217 { "maxfail", o_int, &maxfail,
218 "Maximum number of unsuccessful connection attempts to allow" },
219 { "ktune", o_bool, &tune_kernel,
220 "Alter kernel settings as necessary", 1 },
221 { "noktune", o_bool, &tune_kernel,
222 "Don't alter kernel settings", 0 },
223 { "connect-delay", o_int, &connect_delay,
224 "Maximum time (in ms) to wait after connect script finishes" },
225 { "unit", o_int, &req_unit,
226 "PPP interface unit number to use if possible", OPT_LLIMIT, 0, 0 },
227 #ifdef HAVE_MULTILINK
228 { "multilink", o_bool, &multilink,
229 "Enable multilink operation", 1 },
230 { "nomultilink", o_bool, &multilink,
231 "Disable multilink operation", 0 },
232 { "mp", o_bool, &multilink,
233 "Enable multilink operation", 1 },
234 { "nomp", o_bool, &multilink,
235 "Disable multilink operation", 0 },
236 { "bundle", o_string, &bundle_name,
237 "Bundle name for multilink" },
238 #endif /* HAVE_MULTILINK */
240 { "plugin", o_special, (void *)loadplugin,
241 "Load a plug-in module into pppd", OPT_PRIV },
245 { "pdebug", o_int, &dflag,
246 "libpcap debugging" },
247 { "pass-filter", 1, setpassfilter,
248 "set filter for packets to pass" },
249 { "active-filter", 1, setactivefilter,
250 "set filter for active pkts" },
256 #ifndef IMPLEMENTATION
257 #define IMPLEMENTATION ""
260 static char *usage_string = "\
261 pppd version %s.%d%s\n\
262 Usage: %s [ options ], where options are:\n\
263 <device> Communicate over the named device\n\
264 <speed> Set the baud rate to <speed>\n\
265 <loc>:<rem> Set the local and/or remote interface IP\n\
266 addresses. Either one may be omitted.\n\
267 asyncmap <n> Set the desired async map to hex <n>\n\
268 auth Require authentication from peer\n\
269 connect <p> Invoke shell command <p> to set up the serial line\n\
270 crtscts Use hardware RTS/CTS flow control\n\
271 defaultroute Add default route through interface\n\
272 file <f> Take options from file <f>\n\
273 modem Use modem control lines\n\
274 mru <n> Set MRU value to <n> for negotiation\n\
275 See pppd(8) for more options.\n\
279 * parse_args - parse a string of arguments from the command line.
282 parse_args(argc, argv)
290 privileged_option = privileged;
291 option_source = "command line";
297 * First see if it's an option in the new option list.
299 opt = find_option(arg);
301 int n = n_arguments(opt);
303 option_error("too few parameters for option %s", arg);
306 current_option = arg;
307 if (!process_option(opt, argv))
315 * Maybe a tty name, speed or IP address?
317 if ((ret = setdevname(arg)) == 0
318 && (ret = setspeed(arg)) == 0
319 && (ret = setipaddr(arg)) == 0) {
320 option_error("unrecognized option '%s'", arg);
324 if (ret < 0) /* error */
332 * scan_args - scan the command line arguments to get the tty name,
333 * if specified. Also checks whether the notty or pty option was given.
336 scan_args(argc, argv)
343 privileged_option = privileged;
348 if (strcmp(arg, "notty") == 0 || strcmp(arg, "pty") == 0)
351 /* Skip options and their arguments */
352 opt = find_option(arg);
354 int n = n_arguments(opt);
360 /* Check if it's a tty name and copy it if so */
361 (void) setdevname(arg, 1);
367 * options_from_file - Read a string of options from a file,
368 * and interpret them.
371 options_from_file(filename, must_exist, check_prot, priv)
378 int i, newline, ret, err;
383 char args[MAXARGS][MAXWORDLEN];
384 char cmd[MAXWORDLEN];
388 f = fopen(filename, "r");
395 if (err != ENOENT && err != ENOTDIR)
396 warn("Warning: can't open options file %s: %m", filename);
399 option_error("Can't open options file %s: %m", filename);
403 oldpriv = privileged_option;
404 privileged_option = priv;
405 oldsource = option_source;
406 option_source = strdup(filename);
407 if (option_source == NULL)
408 option_source = "file";
410 while (getword(f, cmd, &newline, filename)) {
412 * First see if it's a command.
414 opt = find_option(cmd);
416 int n = n_arguments(opt);
417 for (i = 0; i < n; ++i) {
418 if (!getword(f, args[i], &newline, filename)) {
420 "In file %s: too few parameters for option '%s'",
426 current_option = cmd;
427 if ((opt->flags & OPT_DEVEQUIV) && no_override) {
428 option_error("the %s option may not be used in the %s file",
432 if (!process_option(opt, argv))
438 * Maybe a tty name, speed or IP address?
440 if ((i = setdevname(cmd)) == 0
441 && (i = setspeed(cmd)) == 0
442 && (i = setipaddr(cmd)) == 0) {
443 option_error("In file %s: unrecognized option '%s'",
447 if (i < 0) /* error */
454 privileged_option = oldpriv;
455 option_source = oldsource;
460 * options_from_user - See if the use has a ~/.ppprc file,
461 * and if so, interpret options from it.
466 char *user, *path, *file;
471 pw = getpwuid(getuid());
472 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
474 file = _PATH_USEROPT;
475 pl = strlen(user) + strlen(file) + 2;
478 novm("init file name");
479 slprintf(path, pl, "%s/%s", user, file);
480 ret = options_from_file(path, 0, 1, privileged);
486 * options_for_tty - See if an options file exists for the serial
487 * device, and if so, interpret options from it.
488 * We only allow the per-tty options file to override anything from
489 * the command line if it is something that the user can't override
490 * once it has been set by root.
495 char *dev, *path, *p;
500 if (strncmp(dev, "/dev/", 5) == 0)
502 if (dev[0] == 0 || strcmp(dev, "tty") == 0)
503 return 1; /* don't look for /etc/ppp/options.tty */
504 pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
507 novm("tty init file name");
508 slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
509 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
510 for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
514 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.
588 struct option_list *list;
591 for (list = extra_options; list != NULL; list = list->next)
592 for (opt = list->options; opt->name != NULL; ++opt)
593 if (strcmp(name, opt->name) == 0)
595 for (opt = general_options; opt->name != NULL; ++opt)
596 if (strcmp(name, opt->name) == 0)
598 for (opt = auth_options; opt->name != NULL; ++opt)
599 if (strcmp(name, opt->name) == 0)
601 for (i = 0; protocols[i] != NULL; ++i)
602 if ((opt = protocols[i]->options) != NULL)
603 for (; opt->name != NULL; ++opt)
604 if (strcmp(name, opt->name) == 0)
610 * process_option - process one new-style option.
613 process_option(opt, argv)
620 int (*parser) __P((char **));
622 if (no_override && (opt->flags & OPT_SEENIT)) {
623 struct option_info *ip = (struct option_info *) opt->addr2;
624 if (!(privileged && (opt->flags & OPT_PRIVFIX)))
628 warn("%s option from per-tty file overrides command line", opt->name);
630 if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
631 option_error("it's too late to use the %s option", opt->name);
634 if ((opt->flags & OPT_PRIV) && !privileged_option) {
635 option_error("using the %s option requires root privilege", opt->name);
638 if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
639 option_error("%s option is disabled", opt->name);
642 if ((opt->flags & OPT_PRIVFIX) && !privileged_option) {
643 struct option_info *ip = (struct option_info *) opt->addr2;
644 if (ip && ip->priv) {
645 option_error("%s option cannot be overridden", opt->name);
649 opt->flags |= OPT_SEENIT;
653 v = opt->flags & OPT_VALUE;
654 *(bool *)(opt->addr) = v;
655 if (opt->addr2 && (opt->flags & OPT_A2COPY))
656 *(bool *)(opt->addr2) = v;
661 if ((opt->flags & OPT_NOARG) == 0) {
662 if (!int_option(*argv, &iv))
664 if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
665 || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
666 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
667 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
668 switch (opt->flags & OPT_LIMITS) {
670 option_error("%s value must be%s >= %d",
671 opt->name, zok, opt->lower_limit);
674 option_error("%s value must be%s <= %d",
675 opt->name, zok, opt->upper_limit);
678 option_error("%s value must be%s between %d and %d",
679 opt->name, opt->lower_limit, opt->upper_limit);
685 a = opt->flags & OPT_VALUE;
687 a -= 256; /* sign extend */
689 if (opt->flags & OPT_INC)
690 iv += *(int *)(opt->addr);
691 if ((opt->flags & OPT_NOINCR) && !privileged_option) {
692 int oldv = *(int *)(opt->addr);
693 if ((opt->flags & OPT_ZEROINF) ?
694 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
695 option_error("%s value cannot be increased", opt->name);
699 *(int *)(opt->addr) = iv;
700 if (opt->addr2 && (opt->flags & OPT_A2COPY))
701 *(int *)(opt->addr2) = iv;
705 if (opt->flags & OPT_NOARG) {
706 v = opt->flags & OPT_VALUE;
707 } else if (!number_option(*argv, &v, 16))
709 if (opt->flags & OPT_OR)
710 v |= *(u_int32_t *)(opt->addr);
711 *(u_int32_t *)(opt->addr) = v;
712 if (opt->addr2 && (opt->flags & OPT_A2COPY))
713 *(u_int32_t *)(opt->addr2) = v;
717 if (opt->flags & OPT_STATIC) {
718 strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
722 novm("option argument");
723 *(char **)(opt->addr) = sv;
727 case o_special_noarg:
729 parser = (int (*) __P((char **))) opt->addr;
730 if (!(*parser)(argv))
736 if (opt->flags & OPT_A2INFO) {
737 struct option_info *ip = (struct option_info *) opt->addr2;
738 ip->priv = privileged_option;
739 ip->source = option_source;
740 } else if ((opt->flags & (OPT_A2COPY|OPT_ENABLE)) == 0)
741 *(bool *)(opt->addr2) = 1;
748 * n_arguments - tell how many arguments an option takes
754 return (opt->type == o_bool || opt->type == o_special_noarg
755 || (opt->flags & OPT_NOARG))? 0: 1;
759 * add_options - add a list of options to the set we grok.
765 struct option_list *list;
767 list = malloc(sizeof(*list));
769 novm("option list entry");
771 list->next = extra_options;
772 extra_options = list;
776 * usage - print out a message telling how to use the program.
781 if (phase == PHASE_INITIALIZE)
782 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
787 * showhelp - print out usage message and exit.
793 if (phase == PHASE_INITIALIZE) {
801 * showversion - print out the version number and exit.
807 if (phase == PHASE_INITIALIZE) {
808 fprintf(stderr, "pppd version %s.%d%s\n",
809 VERSION, PATCHLEVEL, IMPLEMENTATION);
816 * option_error - print a message about an error in an option.
817 * The message is logged, and also sent to
818 * stderr if phase == PHASE_INITIALIZE.
821 option_error __V((char *fmt, ...))
826 #if defined(__STDC__)
831 fmt = va_arg(args, char *);
833 vslprintf(buf, sizeof(buf), fmt, args);
835 if (phase == PHASE_INITIALIZE)
836 fprintf(stderr, "%s: %s\n", progname, buf);
837 syslog(LOG_ERR, "%s", buf);
842 * readable - check if a file is readable by the real user.
855 if (fstat(fd, &sbuf) != 0)
857 if (sbuf.st_uid == uid)
858 return sbuf.st_mode & S_IRUSR;
859 if (sbuf.st_gid == getgid())
860 return sbuf.st_mode & S_IRGRP;
861 for (i = 0; i < ngroups; ++i)
862 if (sbuf.st_gid == groups[i])
863 return sbuf.st_mode & S_IRGRP;
864 return sbuf.st_mode & S_IROTH;
869 * Read a word from a file.
870 * Words are delimited by white-space or by quotes (" or ').
871 * Quotes, white-space and \ may be escaped with \.
872 * \<newline> is ignored.
875 getword(f, word, newlinep, filename)
883 int value, digit, got, n;
885 #define isoctal(c) ((c) >= '0' && (c) < '8')
893 * First skip white-space and comments.
901 * A newline means the end of a comment; backslash-newline
902 * is ignored. Note that we cannot have escape && comment.
914 * Ignore characters other than newline in a comment.
920 * If this character is escaped, we have a word start.
926 * If this is the escape character, look at the next character.
934 * If this is the start of a comment, ignore the rest of the line.
942 * A non-whitespace character is the start of a word.
949 * Save the delimiter for quoted strings.
951 if (!escape && (c == '"' || c == '\'')) {
958 * Process characters until the end of the word.
963 * This character is escaped: backslash-newline is ignored,
964 * various other characters indicate particular values
965 * as for C backslash-escapes.
1000 * \ddd octal sequence
1003 for (n = 0; n < 3 && isoctal(c); ++n) {
1004 value = (value << 3) + (c & 07);
1013 * \x<hex_string> sequence
1017 for (n = 0; n < 2 && isxdigit(c); ++n) {
1018 digit = toupper(c) - '0';
1020 digit += '0' + 10 - 'A';
1021 value = (value << 4) + digit;
1029 * Otherwise the character stands for itself.
1036 * Store the resulting character for the escape sequence.
1038 if (len < MAXWORDLEN-1)
1049 * Not escaped: see if we've reached the end of the word.
1055 if (isspace(c) || c == '#') {
1062 * Backslash starts an escape sequence.
1071 * An ordinary character: store it in the word and get another.
1073 if (len < MAXWORDLEN-1)
1081 * End of the word: check for errors.
1087 option_error("Error reading %s: %m", filename);
1091 * If len is zero, then we didn't find a word before the
1099 * Warn if the word was too long, and append a terminating null.
1101 if (len >= MAXWORDLEN) {
1102 option_error("warning: word in file %s too long (%.20s...)",
1104 len = MAXWORDLEN - 1;
1115 * number_option - parse an unsigned numeric parameter for an option.
1118 number_option(str, valp, base)
1125 *valp = strtoul(str, &ptr, base);
1127 option_error("invalid numeric parameter '%s' for %s option",
1128 str, current_option);
1136 * int_option - like number_option, but valp is int *,
1137 * the base is assumed to be 0, and *valp is not changed
1138 * if there is an error.
1141 int_option(str, valp)
1147 if (!number_option(str, &v, 0))
1155 * The following procedures parse options.
1159 * readfile - take commands from a file.
1165 return options_from_file(*argv, 1, 1, privileged_option);
1169 * callfile - take commands from /etc/ppp/peers/<name>.
1170 * Name may not contain /../, start with / or ../, or end in /..
1176 char *fname, *arg, *p;
1181 if (arg[0] == '/' || arg[0] == 0)
1184 for (p = arg; *p != 0; ) {
1185 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1189 while (*p != '/' && *p != 0)
1196 option_error("call option value may not contain .. or start with /");
1200 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1201 if ((fname = (char *) malloc(l)) == NULL)
1202 novm("call file name");
1203 slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1205 ok = options_from_file(fname, 1, 1, 1);
1213 * setpdebug - Set libpcap debugging level.
1219 return int_option(*argv, &dflag);
1223 * setpassfilter - Set the pass filter for packets
1229 pc.linktype = DLT_PPP;
1230 pc.snapshot = PPP_HDRLEN;
1232 if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1234 option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1239 * setactivefilter - Set the active filter for packets
1242 setactivefilter(argv)
1245 pc.linktype = DLT_PPP;
1246 pc.snapshot = PPP_HDRLEN;
1248 if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1250 option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1256 * noopt - Disable all options.
1262 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1263 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1264 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1265 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1271 * setdomain - Set domain name to append to hostname
1277 if (!privileged_option) {
1278 option_error("using the domain option requires root privilege");
1281 gethostname(hostname, MAXNAMELEN);
1284 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1285 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1287 hostname[MAXNAMELEN-1] = 0;
1293 * setspeed - Set the speed.
1302 if (no_override && inspeed != 0)
1304 spd = strtol(arg, &ptr, 0);
1305 if (ptr == arg || *ptr != 0 || spd == 0)
1307 if (!no_override || inspeed == 0)
1314 * setdevname - Set the device name.
1320 struct stat statbuf;
1321 char dev[MAXPATHLEN];
1326 if (strncmp("/dev/", cp, 5) != 0) {
1327 strlcpy(dev, "/dev/", sizeof(dev));
1328 strlcat(dev, cp, sizeof(dev));
1333 * Check if there is a character device by this name.
1335 if (stat(cp, &statbuf) < 0) {
1336 if (errno == ENOENT)
1338 option_error("Couldn't stat %s: %m", cp);
1341 if (!S_ISCHR(statbuf.st_mode)) {
1342 option_error("%s is not a character device", cp);
1346 if (phase != PHASE_INITIALIZE) {
1347 option_error("device name cannot be changed after initialization");
1351 option_error("per-tty options file may not specify device name");
1355 if (devnam_info.priv && !privileged_option) {
1356 option_error("device name cannot be overridden");
1360 strlcpy(devnam, cp, sizeof(devnam));
1363 devnam_info.priv = privileged_option;
1364 devnam_info.source = option_source;
1371 * setipaddr - Set the IP address
1379 u_int32_t local, remote;
1380 ipcp_options *wo = &ipcp_wantoptions[0];
1381 static int seen_local = 0, seen_remote = 0;
1384 * IP address pair separated by ":".
1386 if ((colon = strchr(arg, ':')) == NULL)
1390 * If colon first character, then no local addr.
1392 if (colon != arg && !(no_override && seen_local)) {
1394 if ((local = inet_addr(arg)) == (u_int32_t) -1) {
1395 if ((hp = gethostbyname(arg)) == NULL) {
1396 option_error("unknown host: %s", arg);
1399 local = *(u_int32_t *)hp->h_addr;
1402 if (bad_ip_adrs(local)) {
1403 option_error("bad local IP address %s", ip_ntoa(local));
1407 wo->ouraddr = local;
1413 * If colon last character, then no remote addr.
1415 if (*++colon != '\0' && !(no_override && seen_remote)) {
1416 if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
1417 if ((hp = gethostbyname(colon)) == NULL) {
1418 option_error("unknown host: %s", colon);
1421 remote = *(u_int32_t *)hp->h_addr;
1422 if (remote_name[0] == 0)
1423 strlcpy(remote_name, colon, sizeof(remote_name));
1426 if (bad_ip_adrs(remote)) {
1427 option_error("bad remote IP address %s", ip_ntoa(remote));
1431 wo->hisaddr = remote;
1440 * setnetmask - set the netmask to be used on the interface.
1451 * Unfortunately, if we use inet_addr, we can't tell whether
1452 * a result of all 1s is an error or a valid 255.255.255.255.
1455 n = parse_dotted_ip(p, &mask);
1459 if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
1460 option_error("invalid netmask value '%s'", *argv);
1469 parse_dotted_ip(p, vp)
1475 char *endp, *p0 = p;
1479 b = strtoul(p, &endp, 0);
1485 /* accept e.g. 0xffffff00 */
1507 if (!privileged_option)
1509 fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
1510 if (fd < 0 && errno == EEXIST)
1511 fd = open(*argv, O_WRONLY | O_APPEND);
1513 if (!privileged_option)
1517 option_error("Can't open log file %s: %m", *argv);
1520 if (log_to_file && log_to_fd >= 0)
1535 void (*init) __P((void));
1537 handle = dlopen(arg, RTLD_GLOBAL | RTLD_NOW);
1541 option_error("%s", err);
1542 option_error("Couldn't load plugin %s", arg);
1545 init = (void (*)(void))dlsym(handle, "plugin_init");
1547 option_error("%s has no initialization entry point", arg);
1551 info("Plugin %s loaded.", arg);