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.11 2004/10/08 07:34:34 tallest Exp $"
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.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 */
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 */
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.
91 parse_args(argc
, argv
)
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) {
101 debug
= nodetach
= 1;
107 idle_time_limit
= atoi(optarg
);
108 if (idle_time_limit
> 0) {
117 strncpy(user
, optarg
, MAXNAMELEN
);
118 strncpy(our_name
, optarg
, MAXNAMELEN
);
119 memset(optarg
, 'X', strlen(optarg
));
122 strncpy(passwd
, optarg
, MAXSECRETLEN
);
123 memset(optarg
, 'X', strlen(optarg
));
126 pppoe_ac_name
= optarg
;
129 pppoe_srv_name
= optarg
;
132 lcp_wantoptions
[0].neg_mru
= 1;
133 lcp_wantoptions
[0].mru
= atoi(optarg
);
136 lcp_allowoptions
[0].mru
= atoi(optarg
);
138 case 'I': // by honor
139 lcp_echo_interval
= atoi(optarg
);
141 case 'T': // by honor
142 lcp_echo_fails
= atoi(optarg
);
144 case 'P': // by honor
147 case 'L': // by honor, support static IP Address
148 inet_aton(optarg
, &Laddr
);
149 ipcp_wantoptions
[0].ouraddr
= Laddr
.s_addr
;
151 case 'N': // by honor
152 retry_num
= atoi(optarg
);
155 req_unit
= atoi(optarg
);
157 case 'R': //by tallest set default route
158 ipcp_wantoptions
[0].default_route
= 1;
160 case 'n': //by tallest for unnumber ip use.
161 #ifdef UNNUMBERIP_SUPPORT
165 case 'C': //by tallest 0407
166 strncpy(ppp_disconnect_func
, optarg
, MAXFUNCLEN
);
168 case 'v': //by tallest 0407
169 retransmit_time
= atoi(optarg
);
175 fprintf(stderr
, usage_string
, argv
[0]);
181 setdevname_pppoe(argv
[optind
]);
183 fprintf(stderr
, usage_string
, argv
[0]);