Merge branch 'tomato-ND-USBmod' into tomato-RT
[tomato.git] / release / src / router / ppp / pppoecd / options.c
bloba619b37528168307c868aa96eda54e4f1657dc0e
1 /*
2 * options.c - handles option processing for PPP.
4 * Copyright (c) 1989 Carnegie Mellon University.
5 * All rights reserved.
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.11 2004/10/08 07:34:34 tallest Exp $"
22 #include <getopt.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <syslog.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include "pppd.h"
30 #include "fsm.h"
31 #include "lcp.h"
32 #include "ipcp.h"
33 #ifdef INET6
34 #include "ipv6cp.h"
35 #endif
37 int debug = 0; /* Debug flag */
38 int kdebugflag = 0; /* Tell kernel to print debug messages */
39 int default_device = 1; /* Using /dev/tty or equivalent */
40 char devnam[MAXPATHLEN]; /* Device name */
41 bool nodetach = 0; /* Don't detach from controlling tty */
42 bool updetach = 0; /* Detach once link is up */
43 int maxconnect = 0; /* Maximum connect time */
44 char user[MAXNAMELEN]; /* Username for PAP */
45 char passwd[MAXSECRETLEN]; /* Password for PAP */
46 //bool persist = 0;
47 bool persist = 1; /* Reopen link after it goes down */
48 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
49 bool demand = 0; /* do dial-on-demand */
50 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
51 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
52 int holdoff = 30; /* # seconds to pause before reconnecting */
53 bool holdoff_specified; /* true if a holdoff value has been given */
54 int log_to_fd = 1; /* send log messages to this fd too */
55 bool log_default = 1; /* log_to_fd is default (stdout) */
56 int maxfail = 0; /* max # of unsuccessful connection attempts */
57 char linkname[MAXPATHLEN]; /* logical name for link */
58 bool tune_kernel = 1; /* may alter kernel settings */
59 int connect_delay = 1000; /* wait this many ms after connect script */
60 int req_unit = -1; /* requested interface unit */
61 char *bundle_name = NULL; /* bundle name for multilink */
62 bool dump_options; /* print out option values */
63 bool dryrun; /* print out option values and exit */
64 char *domain; /* domain name set by domain option */
65 int baud_rate; /* Actual bits/second for serial device */
66 #ifdef UNNUMBERIP_SUPPORT
67 char is_unnumber_ip = 0; /* This parameter use for unnumber IP. by tallest */
68 #endif
69 char ppp_disconnect_func[MAXFUNCLEN]; /* This is a function for dial on demand disconnection using. by tallest 0407 */
71 int logmask = LOG_NOTICE; // more logging -- zzz
73 char *current_option; /* the name of the option being parsed */
74 int privileged_option; /* set iff the current option came from root */
75 char *option_source; /* string saying where the option came from */
76 int option_priority = OPRIO_CFGFILE; /* priority of the current options */
77 bool devnam_fixed; /* can no longer change device name */
79 extern char *pppoe_ac_name;
80 extern char *pppoe_srv_name;
81 extern int lcp_echo_interval; /* Interval between LCP echo-requests */
82 extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */
83 extern int retry_num; /* interval of send disc */
84 extern int retransmit_time;
86 extern int setdevname_pppoe(const char *cp);
88 static char *usage_string = "usage: %s interface -d -k [-i idle] [-u username] [-p passwd] [-a acname] [-s srvname] [-r mru] [-t mtu] [-I lcp_echo_interval] [-T lcp_echo_fails] [-P ipparam] [-L Local IP] [-N retry_num] [-R set default route]"
89 #ifdef INET6
90 " [-6 enable PPP IPv6CP]"
91 #endif
92 " [-n use unnumber ip] [-C disconnected function]\n";
95 * parse_args - parse a string of arguments from the command line.
97 int
98 parse_args(argc, argv)
99 int argc;
100 char **argv;
102 int opt;
103 struct in_addr Laddr; //, Naddr;
105 while ((opt = getopt(argc, argv, "dki:u:p:a:s:r:t:U:I:T:P:L:N:R6nC:v:x")) != -1) {
106 switch (opt) {
107 case 'd':
108 debug = nodetach = 1;
109 break;
110 case 'k':
111 persist = 1;
112 break;
113 case 'i':
114 idle_time_limit = atoi(optarg);
115 if (idle_time_limit > 0) {
116 demand = 1;
117 maxfail = 0;
119 else {
120 maxfail = 10;
122 break;
123 case 'u':
124 strncpy(user, optarg, MAXNAMELEN);
125 strncpy(our_name, optarg, MAXNAMELEN);
126 memset(optarg, 'X', strlen(optarg));
127 break;
128 case 'p':
129 strncpy(passwd, optarg, MAXSECRETLEN);
130 memset(optarg, 'X', strlen(optarg));
131 break;
132 case 'a':
133 pppoe_ac_name = optarg;
134 break;
135 case 's':
136 pppoe_srv_name = optarg;
137 break;
138 case 'r':
139 lcp_wantoptions[0].neg_mru = 1;
140 lcp_wantoptions[0].mru = atoi(optarg);
141 break;
142 case 't':
143 lcp_allowoptions[0].mru = atoi(optarg);
144 break;
145 case 'I': // by honor
146 lcp_echo_interval = atoi(optarg);
147 break;
148 case 'T': // by honor
149 lcp_echo_fails = atoi(optarg);
150 break;
151 case 'P': // by honor
152 ipparam = optarg;
153 break;
154 case 'L': // by honor, support static IP Address
155 inet_aton(optarg, &Laddr);
156 ipcp_wantoptions[0].ouraddr = Laddr.s_addr;
157 break;
158 case 'N': // by honor
159 retry_num = atoi(optarg);
160 break;
161 case 'U':
162 req_unit = atoi(optarg);
163 break;
164 case 'R': //by tallest set default route
165 ipcp_wantoptions[0].default_route = 1;
166 break;
167 case '6': //by Polaris75 - enable IPv6CP
168 #ifdef INET6
169 ipv6cp_protent.enabled_flag = 1;
170 #endif
171 break;
172 case 'n': //by tallest for unnumber ip use.
173 #ifdef UNNUMBERIP_SUPPORT
174 is_unnumber_ip = 1;
175 #endif
176 break;
177 case 'C': //by tallest 0407
178 strncpy(ppp_disconnect_func, optarg, MAXFUNCLEN);
179 break;
180 case 'v': //by tallest 0407
181 retransmit_time = atoi(optarg);
182 break;
183 case 'x': // zzz
184 logmask = LOG_INFO;
185 break;
186 default:
187 fprintf(stderr, usage_string, argv[0]);
188 return 0;
192 if (optind < argc)
193 setdevname_pppoe(argv[optind]);
194 else {
195 fprintf(stderr, usage_string, argv[0]);
196 return 0;
199 return 1;