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