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>
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 */
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 */
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]"
90 " [-6 enable PPP IPv6CP]"
92 " [-n use unnumber ip] [-C disconnected function]\n";
95 * parse_args - parse a string of arguments from the command line.
98 parse_args(argc
, argv
)
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) {
108 debug
= nodetach
= 1;
114 idle_time_limit
= atoi(optarg
);
115 if (idle_time_limit
> 0) {
124 strncpy(user
, optarg
, MAXNAMELEN
);
125 strncpy(our_name
, optarg
, MAXNAMELEN
);
126 memset(optarg
, 'X', strlen(optarg
));
129 strncpy(passwd
, optarg
, MAXSECRETLEN
);
130 memset(optarg
, 'X', strlen(optarg
));
133 pppoe_ac_name
= optarg
;
136 pppoe_srv_name
= optarg
;
139 lcp_wantoptions
[0].neg_mru
= 1;
140 lcp_wantoptions
[0].mru
= atoi(optarg
);
143 lcp_allowoptions
[0].mru
= atoi(optarg
);
145 case 'I': // by honor
146 lcp_echo_interval
= atoi(optarg
);
148 case 'T': // by honor
149 lcp_echo_fails
= atoi(optarg
);
151 case 'P': // by honor
154 case 'L': // by honor, support static IP Address
155 inet_aton(optarg
, &Laddr
);
156 ipcp_wantoptions
[0].ouraddr
= Laddr
.s_addr
;
158 case 'N': // by honor
159 retry_num
= atoi(optarg
);
162 req_unit
= atoi(optarg
);
164 case 'R': //by tallest set default route
165 ipcp_wantoptions
[0].default_route
= 1;
167 case '6': //by Polaris75 - enable IPv6CP
169 ipv6cp_protent
.enabled_flag
= 1;
172 case 'n': //by tallest for unnumber ip use.
173 #ifdef UNNUMBERIP_SUPPORT
177 case 'C': //by tallest 0407
178 strncpy(ppp_disconnect_func
, optarg
, MAXFUNCLEN
);
180 case 'v': //by tallest 0407
181 retransmit_time
= atoi(optarg
);
187 fprintf(stderr
, usage_string
, argv
[0]);
193 setdevname_pppoe(argv
[optind
]);
195 fprintf(stderr
, usage_string
, argv
[0]);