From 65201e4a29bed7b7e256d2bf91e217a0433c2a08 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Fri, 10 Oct 1997 09:28:38 +0000 Subject: [PATCH] Revive the connect-max-attempts option. When running in persist mode, this limits the number of retries before aborting. This can save expensive phone bills. :-) See rev 1.6 of main.c for original. --- usr.sbin/pppd/main.c | 14 ++++++++++++-- usr.sbin/pppd/options.c | 12 +++++++++++- usr.sbin/pppd/pppd.8 | 7 ++++++- usr.sbin/pppd/pppd.h | 3 ++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index 916bd243def..a54c22e8fc5 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: main.c,v 1.13 1997/08/19 17:52:43 peter Exp $"; +static char rcsid[] = "$Id: main.c,v 1.14 1997/08/22 12:03:55 peter Exp $"; #endif #include @@ -175,6 +175,7 @@ main(argc, argv) sigset_t mask; struct protent *protp; struct stat statbuf; + int connect_attempts = 0; phase = PHASE_INITIALIZE; p = ttyname(0); @@ -472,6 +473,7 @@ main(argc, argv) if (device_script(connector, ttyfd, ttyfd) < 0) { syslog(LOG_ERR, "Connect script failed"); setdtr(ttyfd, FALSE); + connect_attempts++; goto fail; } @@ -479,6 +481,8 @@ main(argc, argv) sleep(1); /* give it time to set up its terminal */ } + connect_attempts = 0; /* we made it through ok */ + /* set line speed, flow control, etc.; clear CLOCAL if modem option */ set_up_tty(ttyfd, 0); @@ -487,7 +491,8 @@ main(argc, argv) while ((i = open(devnam, O_RDWR)) < 0) { if (errno != EINTR) syslog(LOG_ERR, "Failed to reopen %s: %m", devnam); - if (!persist || errno != EINTR || hungup || kill_link) + if (!persist || errno != EINTR || + hungup || kill_link) goto fail; } close(i); @@ -602,6 +607,11 @@ main(argc, argv) iffilename[0] = 0; } + /* limit to retries? */ + if (max_con_attempts) + if (connect_attempts >= max_con_attempts) + break; + if (!persist) break; diff --git a/usr.sbin/pppd/options.c b/usr.sbin/pppd/options.c index 0b34449f583..0fc7ab05ac1 100644 --- a/usr.sbin/pppd/options.c +++ b/usr.sbin/pppd/options.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: options.c,v 1.14 1997/08/22 15:50:09 peter Exp $"; +static char rcsid[] = "$Id: options.c,v 1.15 1997/10/10 06:02:56 peter Exp $"; #endif #include @@ -90,6 +90,7 @@ int nodetach = 0; /* Don't detach from controlling tty */ char *connector = NULL; /* Script to establish physical link */ char *disconnector = NULL; /* Script to disestablish physical link */ char *welcomer = NULL; /* Script to run after phys link estab. */ +int max_con_attempts = 0; /* Maximum connect tries in non-demand mode */ int maxconnect = 0; /* Maximum connect time */ char user[MAXNAMELEN]; /* Username for PAP */ char passwd[MAXSECRETLEN]; /* Password for PAP */ @@ -165,6 +166,7 @@ static int nopcomp __P((char **)); static int setconnector __P((char **)); static int setdisconnector __P((char **)); static int setwelcomer __P((char **)); +static int setmaxcon __P((char **)); static int setmaxconnect __P((char **)); static int setdomain __P((char **)); static int setnetmask __P((char **)); @@ -303,6 +305,7 @@ static struct cmd { {"connect", 1, setconnector}, /* A program to set up a connection */ {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */ {"welcome", 1, setwelcomer},/* Script to welcome client */ + {"connect-max-attempts", 1, setmaxcon}, /* maximum # connect attempts */ {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */ {"crtscts", 0, setcrtscts}, /* set h/w flow control */ {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */ @@ -1531,6 +1534,13 @@ setwelcomer(argv) return (1); } +static int +setmaxcon(argv) + char **argv; +{ + return int_option(*argv, &max_con_attempts); +} + /* * setmaxconnect - Set the maximum connect time */ diff --git a/usr.sbin/pppd/pppd.8 b/usr.sbin/pppd/pppd.8 index a54dae24fff..e45a7f70e8a 100644 --- a/usr.sbin/pppd/pppd.8 +++ b/usr.sbin/pppd/pppd.8 @@ -1,5 +1,5 @@ .\" manual page [] for pppd 2.3 -.\" $Id: pppd.8,v 1.14 1997/08/19 17:52:46 peter Exp $ +.\" $Id: pppd.8,v 1.15 1997/10/10 06:30:08 peter Exp $ .\" SH section heading .\" SS subsection heading .\" LP paragraph @@ -91,6 +91,11 @@ up the serial line. This script would typically use the chat(8) program to dial the modem and start the remote ppp session. This option is privileged if the \fInoauth\fR option is used. .TP +.B connect-max-attempts \fI +Attempt dial-out connection to remote system no more than specified number +of times (default = 1). If the connection is not made, pppd will exit. +Requires that \fBpersist\fR has been specified. +.TP .B crtscts Use hardware flow control (i.e. RTS/CTS) to control the flow of data on the serial port. If neither the \fIcrtscts\fR nor the diff --git a/usr.sbin/pppd/pppd.h b/usr.sbin/pppd/pppd.h index 88d161781ed..e1a63b77556 100644 --- a/usr.sbin/pppd/pppd.h +++ b/usr.sbin/pppd/pppd.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pppd.h,v 1.9 1997/08/19 17:52:46 peter Exp $ + * $Id: pppd.h,v 1.10 1997/10/10 06:02:57 peter Exp $ */ /* @@ -86,6 +86,7 @@ extern int nodetach; /* Don't detach from controlling tty */ extern char *connector; /* Script to establish physical link */ extern char *disconnector; /* Script to disestablish physical link */ extern char *welcomer; /* Script to welcome client after connection */ +extern int max_con_attempts;/* Maximum number of times to try dialing */ extern int maxconnect; /* Maximum connect time (seconds) */ extern char user[]; /* Our name for authenticating ourselves */ extern char passwd[]; /* Password for PAP */