1/* 2 * options.c - handles option processing for PPP. 3 * 4 * Copyright (c) 1989 Carnegie Mellon University. 5 * All rights reserved. 6 * 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. 18 */ 19 20#define RCSID "$Id: options.c,v 1.1.1.1 2008/10/15 03:30:13 james26_jang Exp $" 21 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 34int debug = 0; /* Debug flag */ 35int kdebugflag = 0; /* Tell kernel to print debug messages */ 36int default_device = 1; /* Using /dev/tty or equivalent */ 37char devnam[MAXPATHLEN]; /* Device name */ 38bool nodetach = 0; /* Don't detach from controlling tty */ 39bool updetach = 0; /* Detach once link is up */ 40int maxconnect = 0; /* Maximum connect time */ 41char user[MAXNAMELEN]; /* Username for PAP */ 42char passwd[MAXSECRETLEN]; /* Password for PAP */ 43bool persist = 0; /* Reopen link after it goes down */ 44char our_name[MAXNAMELEN]; /* Our name for authentication purposes */ 45bool demand = 0; /* do dial-on-demand */ 46char *ipparam = NULL; /* Extra parameter for ip up/down scripts */ 47int idle_time_limit = 0; /* Disconnect if idle for this many seconds */ 48int holdoff = 30; /* # seconds to pause before reconnecting */ 49bool holdoff_specified; /* true if a holdoff value has been given */ 50int log_to_fd = 1; /* send log messages to this fd too */ 51bool log_default = 1; /* log_to_fd is default (stdout) */ 52int maxfail = 10; /* max # of unsuccessful connection attempts */ 53char linkname[MAXPATHLEN]; /* logical name for link */ 54bool tune_kernel = 1; /* may alter kernel settings */ 55int connect_delay = 1000; /* wait this many ms after connect script */ 56int req_unit = -1; /* requested interface unit */ 57char *bundle_name = NULL; /* bundle name for multilink */ 58bool dump_options; /* print out option values */ 59bool dryrun; /* print out option values and exit */ 60char *domain; /* domain name set by domain option */ 61int baud_rate; /* Actual bits/second for serial device */ 62bool tx_only = 0; /* JY: For counting tx packet as idle time */ 63 64char *current_option; /* the name of the option being parsed */ 65int privileged_option; /* set iff the current option came from root */ 66char *option_source; /* string saying where the option came from */ 67int option_priority = OPRIO_CFGFILE; /* priority of the current options */ 68bool devnam_fixed; /* can no longer change device name */ 69 70extern char *pppoe_ac_name; 71extern char *pppoe_srv_name; 72extern int lcp_echo_interval; /* Interval between LCP echo-requests */ 73extern int lcp_echo_fails; /* Tolerance to unanswered echo-requests */ 74extern int retry_num; /* interval of send disc */ 75 76extern int setdevname_pppoe(const char *cp); 77 78static 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] [-o]\n"; 79 80/* 81 * parse_args - parse a string of arguments from the command line. 82 */ 83int 84parse_args(argc, argv) 85 int argc; 86 char **argv; 87{ 88 int opt; 89 struct in_addr Laddr, Naddr; 90 91 while ((opt = getopt(argc, argv, "dkoi:u:p:a:s:r:t:U:I:T:P:L:N:")) != -1) { 92 switch (opt) { 93 case 'd': 94 debug = nodetach = 1; 95 break; 96 case 'k': 97 persist = 1; 98 break; 99 case 'o': 100 tx_only = 1; 101 break; 102 case 'i': 103 idle_time_limit = atoi(optarg); 104 if (idle_time_limit > 0) 105 demand = 1; 106 break; 107 case 'u': 108 strncpy(user, optarg, MAXNAMELEN); 109 strncpy(our_name, optarg, MAXNAMELEN); 110 break; 111 case 'p': 112 strncpy(passwd, optarg, MAXSECRETLEN); 113 break; 114 case 'a': 115 pppoe_ac_name = optarg; 116 break; 117 case 's': 118 pppoe_srv_name = optarg; 119 break; 120 case 'r': 121 lcp_wantoptions[0].neg_mru = 1; 122 lcp_wantoptions[0].mru = atoi(optarg); 123 break; 124 case 't': 125 lcp_allowoptions[0].mru = atoi(optarg); 126 break; 127 case 'I': 128 lcp_echo_interval = atoi(optarg); 129 break; 130 case 'T': 131 lcp_echo_fails = atoi(optarg); 132 break; 133 case 'P': 134 ipparam = optarg; 135 break; 136 case 'L': 137 inet_aton(optarg, &Laddr); 138 ipcp_wantoptions[0].ouraddr = Laddr.s_addr; 139 break; 140 case 'N': 141 retry_num = atoi(optarg); 142 break; 143 case 'U': 144 req_unit = atoi(optarg); 145 break; 146 default: 147 fprintf(stderr, usage_string, argv[0]); 148 return 0; 149 } 150 } 151 152 if (optind < argc) 153 setdevname_pppoe(argv[optind]); 154 else { 155 fprintf(stderr, usage_string, argv[0]); 156 return 0; 157 } 158 159 return 1; 160} 161