From 6f9174716453eb7f8571eccc48c1683947da2514 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 12 Jun 1995 12:02:25 +0000 Subject: [PATCH] Give up waiting for a PAP auth-req from the peer after 30 seconds. --- pppd/.cvsignore | 2 ++ pppd/options.c | 31 ++++++++++++++++++++----------- pppd/pppd.8 | 8 +++++++- pppd/upap.c | 37 +++++++++++++++++++++++++++++++++---- pppd/upap.h | 8 +++++--- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/pppd/.cvsignore b/pppd/.cvsignore index f3c7a7c..7ee9db2 100644 --- a/pppd/.cvsignore +++ b/pppd/.cvsignore @@ -1 +1,3 @@ Makefile +pppd +pppd.0 diff --git a/pppd/options.c b/pppd/options.c index 2375cf5..b54f95a 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: options.c,v 1.20 1995/06/12 11:22:51 paulus Exp $"; +static char rcsid[] = "$Id: options.c,v 1.21 1995/06/12 12:02:20 paulus Exp $"; #endif #include @@ -153,6 +153,7 @@ static int setipcpconf __P((char **)); static int setipcpfails __P((char **)); static int setpaptimeout __P((char **)); static int setpapreqs __P((char **)); +static int setpapreqtime __P((char **)); static int setchaptimeout __P((char **)); static int setchapchal __P((char **)); static int setchapintv __P((char **)); @@ -165,7 +166,7 @@ static int setnobsdcomp __P((void)); static int setipparam __P((char **)); static int setpapcrypt __P((void)); -static int number_option __P((char *, long *, int)); +static int number_option __P((char *, u_int32_t *, int)); static int readable __P((int fd)); void usage(); @@ -236,8 +237,9 @@ static struct cmd { {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */ {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */ {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */ - {"pap-restart", 1, setpaptimeout}, /* Set timeout for UPAP */ + {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */ {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */ + {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */ {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */ {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */ {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */ @@ -495,7 +497,7 @@ readable(fd) /* * Read a word from a file. - * Words are delimited by white-space or by quotes (", or '). + * Words are delimited by white-space or by quotes (" or '). * Quotes, white-space and \ may be escaped with \. * \ is ignored. */ @@ -741,17 +743,17 @@ getword(f, word, newlinep, filename) } /* - * number_option - parse a numeric parameter for an option + * number_option - parse an unsigned numeric parameter for an option. */ static int number_option(str, valp, base) char *str; - long *valp; + u_int32_t *valp; int base; { char *ptr; - *valp = strtol(str, &ptr, base); + *valp = strtoul(str, &ptr, base); if (ptr == str) { fprintf(stderr, "%s: invalid number: %s\n", progname, str); return 0; @@ -770,7 +772,7 @@ int_option(str, valp) char *str; int *valp; { - long v; + u_int32_t v; if (!number_option(str, &v, 0)) return 0; @@ -893,7 +895,7 @@ static int setmru(argv) char **argv; { - long mru; + u_int32_t mru; if (!number_option(*argv, &mru, 0)) return 0; @@ -910,7 +912,7 @@ static int setmtu(argv) char **argv; { - long mtu; + u_int32_t mtu; if (!number_option(*argv, &mtu, 0)) return 0; @@ -1143,7 +1145,7 @@ static int setasyncmap(argv) char **argv; { - long asyncmap; + u_int32_t asyncmap; if (!number_option(*argv, &asyncmap, 16)) return 0; @@ -1598,6 +1600,13 @@ setpaptimeout(argv) return int_option(*argv, &upap[0].us_timeouttime); } +static int +setpapreqtime(argv) + char **argv; +{ + return int_option(*argv, &upap[0].us_reqtimeout); +} + static int setpapreqs(argv) char **argv; diff --git a/pppd/pppd.8 b/pppd/pppd.8 index 2866f07..c210d05 100644 --- a/pppd/pppd.8 +++ b/pppd/pppd.8 @@ -1,5 +1,5 @@ .\" manual page [] for pppd 2.0 -.\" $Id: pppd.8,v 1.11 1995/05/01 01:46:40 paulus Exp $ +.\" $Id: pppd.8,v 1.12 1995/06/12 12:02:22 paulus Exp $ .\" SH section heading .\" SS subsection heading .\" LP paragraph @@ -395,6 +395,12 @@ Set the PAP restart interval (retransmission timeout) to seconds Set the maximum number of PAP authenticate-request transmissions to (default 10). .TP +.B pap-timeout \fI +Set the maximum time that +.I pppd +will wait for the peer to authenticate itself with PAP to + seconds (0 means no limit). +.TP .B chap-restart \fI Set the CHAP restart interval (retransmission timeout for challenges) to seconds (default 3). diff --git a/pppd/upap.c b/pppd/upap.c index afbc180..aed4a7b 100644 --- a/pppd/upap.c +++ b/pppd/upap.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: upap.c,v 1.5 1994/10/24 04:31:11 paulus Exp $"; +static char rcsid[] = "$Id: upap.c,v 1.6 1995/06/12 12:02:24 paulus Exp $"; #endif /* @@ -39,6 +39,7 @@ upap_state upap[NUM_PPP]; /* UPAP state; one for each unit */ static void upap_timeout __P((caddr_t)); +static void upap_reqtimeout __P((caddr_t)); static void upap_rauthreq __P((upap_state *, u_char *, int, int)); static void upap_rauthack __P((upap_state *, u_char *, int, int)); static void upap_rauthnak __P((upap_state *, u_char *, int, int)); @@ -65,6 +66,7 @@ upap_init(unit) u->us_id = 0; u->us_timeouttime = UPAP_DEFTIMEOUT; u->us_maxtransmits = 10; + u->us_reqtimeout = UPAP_DEFREQTIME; } @@ -117,11 +119,13 @@ upap_authpeer(unit) } u->us_serverstate = UPAPSS_LISTEN; + if (u->us_reqtimeout > 0) + TIMEOUT(upap_reqtimeout, (caddr_t) u, u->us_reqtimeout); } /* - * upap_timeout - Timeout expired. + * upap_timeout - Retransmission timer for sending auth-reqs expired. */ static void upap_timeout(arg) @@ -144,6 +148,23 @@ upap_timeout(arg) } +/* + * upap_reqtimeout - Give up waiting for the peer to send an auth-req. + */ +static void +upap_reqtimeout(arg) + caddr_t arg; +{ + upap_state *u = (upap_state *) arg; + + if (u->us_serverstate != UPAPSS_LISTEN) + return; /* huh?? */ + + auth_peer_fail(u->us_unit, PPP_PAP); + u->us_serverstate = UPAPSS_BADAUTH; +} + + /* * upap_lowerup - The lower layer is up. * @@ -163,8 +184,11 @@ upap_lowerup(unit) if (u->us_serverstate == UPAPSS_INITIAL) u->us_serverstate = UPAPSS_CLOSED; - else if (u->us_serverstate == UPAPSS_PENDING) + else if (u->us_serverstate == UPAPSS_PENDING) { u->us_serverstate = UPAPSS_LISTEN; + if (u->us_reqtimeout > 0) + TIMEOUT(upap_reqtimeout, (caddr_t) u, u->us_reqtimeout); + } } @@ -179,8 +203,10 @@ upap_lowerdown(unit) { upap_state *u = &upap[unit]; - if (u->us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */ + if (u->us_clientstate == UPAPCS_AUTHREQ) /* Timeout pending? */ UNTIMEOUT(upap_timeout, (caddr_t) u); /* Cancel timeout */ + if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) + UNTIMEOUT(upap_reqtimeout, (caddr_t) u); u->us_clientstate = UPAPCS_INITIAL; u->us_serverstate = UPAPSS_INITIAL; @@ -339,6 +365,9 @@ upap_rauthreq(u, inp, id, len) u->us_serverstate = UPAPSS_BADAUTH; auth_peer_fail(u->us_unit, PPP_PAP); } + + if (u->us_reqtimeout > 0) + UNTIMEOUT(upap_reqtimeout, (caddr_t) u); } diff --git a/pppd/upap.h b/pppd/upap.h index 4dfdeaf..8b15019 100644 --- a/pppd/upap.h +++ b/pppd/upap.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: upap.h,v 1.3 1994/09/21 06:47:37 paulus Exp $ + * $Id: upap.h,v 1.4 1995/06/12 12:02:25 paulus Exp $ */ /* @@ -45,9 +45,10 @@ typedef struct upap_state { int us_clientstate; /* Client state */ int us_serverstate; /* Server state */ u_char us_id; /* Current id */ - int us_timeouttime; /* Timeout time in milliseconds */ + int us_timeouttime; /* Timeout (seconds) for auth-req retrans. */ int us_transmits; /* Number of auth-reqs sent */ int us_maxtransmits; /* Maximum number of auth-reqs to send */ + int us_reqtimeout; /* Time to wait for auth-req from peer */ } upap_state; @@ -75,7 +76,8 @@ typedef struct upap_state { /* * Timeouts. */ -#define UPAP_DEFTIMEOUT 3 /* Timeout time in seconds */ +#define UPAP_DEFTIMEOUT 3 /* Timeout (seconds) for retransmitting req */ +#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ extern upap_state upap[]; -- 2.39.2