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