diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index 7e1a9e461e5f..758fe0d60927 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: chap.c,v 1.28 1997/12/24 09:28:53 brian Exp $ + * $Id: chap.c,v 1.28.2.1 1998/01/29 00:49:13 brian Exp $ * * TODO: */ @@ -266,14 +266,13 @@ RecvChapResult(struct fsmheader *chp, struct mbuf *bp, struct physical *physical) { int len; - struct lcpstate *lcp = &LcpInfo; len = ntohs(chp->length); LogPrintf(LogDEBUG, "RecvChapResult: length: %d\n", len); if (chp->code == CHAP_SUCCESS) { - if (lcp->auth_iwait == PROTO_CHAP) { - lcp->auth_iwait = 0; - if (lcp->auth_ineed == 0) + if (LcpInfo.auth_iwait == PROTO_CHAP) { + LcpInfo.auth_iwait = 0; + if (LcpInfo.auth_ineed == 0) NewPhase(physical, PHASE_NETWORK); } } else { diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c index 817ad170c863..93ff3aa0b165 100644 --- a/usr.sbin/ppp/deflate.c +++ b/usr.sbin/ppp/deflate.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: deflate.c,v 1.6 1998/01/10 01:55:09 brian Exp $ + * $Id: deflate.c,v 1.6.4.1 1998/01/29 00:49:16 brian Exp $ */ #include @@ -40,10 +40,10 @@ #include "loadalias.h" #include "vars.h" #include "hdlc.h" +#include "timer.h" #include "lcp.h" #include "ccp.h" #include "lcpproto.h" -#include "timer.h" #include "fsm.h" #include "deflate.h" diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index 079836c1a2d7..1ee4414f92e2 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -17,10 +17,9 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lcp.c,v 1.55.2.1 1998/01/29 00:49:24 brian Exp $ + * $Id: lcp.c,v 1.55.2.2 1998/01/29 23:11:38 brian Exp $ * * TODO: - * o Validate magic number received from peer. * o Limit data field length by MRU */ #include @@ -143,28 +142,27 @@ struct fsm LcpFsm = { LcpDecodeConfig, }; -static struct pppTimer LcpReportTimer; -static int LcpFailedMagic; - static void LcpReportTime(void *data) { + struct pppTimer *me = (struct pppTimer *)data; + if (LogIsKept(LogDEBUG)) { time_t t; time(&t); LogPrintf(LogDEBUG, "LcpReportTime: %s\n", ctime(&t)); } - StopTimer(&LcpReportTimer); - LcpReportTimer.state = TIMER_STOPPED; - StartTimer(&LcpReportTimer); + + StopTimer(me); + me->state = TIMER_STOPPED; + StartTimer(me); HdlcErrorCheck(); } int ReportLcpStatus(struct cmdargs const *arg) { - struct lcpstate *lcp = &LcpInfo; struct fsm *fp = &LcpFsm; if (!VarTerm) @@ -174,13 +172,13 @@ ReportLcpStatus(struct cmdargs const *arg) fprintf(VarTerm, " his side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n" " MAGIC %08lx, REJECT %04x\n", - lcp->his_mru, (u_long)lcp->his_accmap, lcp->his_protocomp, - lcp->his_acfcomp, (u_long)lcp->his_magic, lcp->his_reject); + LcpInfo.his_mru, (u_long)LcpInfo.his_accmap, LcpInfo.his_protocomp, + LcpInfo.his_acfcomp, (u_long)LcpInfo.his_magic, LcpInfo.his_reject); fprintf(VarTerm, " my side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n" " MAGIC %08lx, REJECT %04x\n", - lcp->want_mru, (u_long)lcp->want_accmap, lcp->want_protocomp, - lcp->want_acfcomp, (u_long)lcp->want_magic, lcp->my_reject); + LcpInfo.want_mru, (u_long)LcpInfo.want_accmap, LcpInfo.want_protocomp, + LcpInfo.want_acfcomp, (u_long)LcpInfo.want_magic, LcpInfo.my_reject); fprintf(VarTerm, "\nDefaults: MRU = %d, ACCMAP = %08lx\t", VarMRU, (u_long)VarAccmap); fprintf(VarTerm, "Open Mode: %s", @@ -204,28 +202,25 @@ GenerateMagic(void) void LcpInit(struct physical *physical) { - struct lcpstate *lcp = &LcpInfo; - FsmInit(&LcpFsm, physical); HdlcInit(); - - memset(lcp, '\0', sizeof(struct lcpstate)); - lcp->want_mru = VarMRU; - lcp->his_mru = DEF_MRU; - lcp->his_accmap = 0xffffffff; - lcp->want_accmap = VarAccmap; - lcp->want_magic = GenerateMagic(); - lcp->want_auth = lcp->his_auth = 0; + memset(&LcpInfo, '\0', sizeof LcpInfo); + LcpInfo.want_mru = VarMRU; + LcpInfo.his_mru = DEF_MRU; + LcpInfo.his_accmap = 0xffffffff; + LcpInfo.want_accmap = VarAccmap; + LcpInfo.want_magic = GenerateMagic(); + LcpInfo.want_auth = LcpInfo.his_auth = 0; if (Enabled(ConfChap)) - lcp->want_auth = PROTO_CHAP; + LcpInfo.want_auth = PROTO_CHAP; else if (Enabled(ConfPap)) - lcp->want_auth = PROTO_PAP; + LcpInfo.want_auth = PROTO_PAP; if (Enabled(ConfLqr)) - lcp->want_lqrperiod = VarLqrTimeout * 100; + LcpInfo.want_lqrperiod = VarLqrTimeout * 100; if (Enabled(ConfAcfcomp)) - lcp->want_acfcomp = 1; + LcpInfo.want_acfcomp = 1; if (Enabled(ConfProtocomp)) - lcp->want_protocomp = 1; + LcpInfo.want_protocomp = 1; LcpFsm.maxconfig = 10; } @@ -318,32 +313,31 @@ static void LcpSendConfigReq(struct fsm * fp) { u_char *cp; - struct lcpstate *lcp = &LcpInfo; struct lcp_opt o; LogPrintf(LogLCP, "LcpSendConfigReq\n"); cp = ReqBuff; if (!Physical_IsSync(fp->physical)) { - if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) + if (LcpInfo.want_acfcomp && !REJECTED(&LcpInfo, TY_ACFCOMP)) PUTN(TY_ACFCOMP); - if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) + if (LcpInfo.want_protocomp && !REJECTED(&LcpInfo, TY_PROTOCOMP)) PUTN(TY_PROTOCOMP); - if (!REJECTED(lcp, TY_ACCMAP)) - PUTACCMAP(lcp->want_accmap); + if (!REJECTED(&LcpInfo, TY_ACCMAP)) + PUTACCMAP(LcpInfo.want_accmap); } - if (!REJECTED(lcp, TY_MRU)) - PUTMRU(lcp->want_mru); + if (!REJECTED(&LcpInfo, TY_MRU)) + PUTMRU(LcpInfo.want_mru); - if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM)) - PUTMAGIC(lcp->want_magic); + if (LcpInfo.want_magic && !REJECTED(&LcpInfo, TY_MAGICNUM)) + PUTMAGIC(LcpInfo.want_magic); - if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) - PUTLQR(lcp->want_lqrperiod); + if (LcpInfo.want_lqrperiod && !REJECTED(&LcpInfo, TY_QUALPROTO)) + PUTLQR(LcpInfo.want_lqrperiod); - switch (lcp->want_auth) { + switch (LcpInfo.want_auth) { case PROTO_PAP: PUTPAP(); break; @@ -372,7 +366,7 @@ LcpSendProtoRej(u_char * option, int count) static void LcpSendTerminateReq(struct fsm * fp) { - /* Most thins are done in fsm layer. Nothing to to. */ + /* Fsm has just send a terminate request */ } static void @@ -392,7 +386,7 @@ LcpLayerStart(struct fsm * fp) static void StopAllTimers(void) { - StopTimer(&LcpReportTimer); + StopTimer(&LcpInfo.ReportTimer); StopIdleTimer(); StopTimer(&AuthPapInfo.authtimer); StopTimer(&AuthChapInfo.authtimer); @@ -423,11 +417,12 @@ LcpLayerUp(struct fsm * fp) NewPhase(fp->physical, PHASE_AUTHENTICATE); StartLqm(fp->physical); - StopTimer(&LcpReportTimer); - LcpReportTimer.state = TIMER_STOPPED; - LcpReportTimer.load = 60 * SECTICKS; - LcpReportTimer.func = LcpReportTime; - StartTimer(&LcpReportTimer); + StopTimer(&LcpInfo.ReportTimer); + LcpInfo.ReportTimer.state = TIMER_STOPPED; + LcpInfo.ReportTimer.load = 60 * SECTICKS; + LcpInfo.ReportTimer.arg = &LcpInfo.ReportTimer; + LcpInfo.ReportTimer.func = LcpReportTime; + StartTimer(&LcpInfo.ReportTimer); } static void @@ -446,13 +441,13 @@ void LcpUp() { FsmUp(&LcpFsm); - LcpFailedMagic = 0; + LcpInfo.LcpFailedMagic = 0; } void LcpDown() { /* Sudden death */ - LcpFailedMagic = 0; + LcpInfo.LcpFailedMagic = 0; FsmDown(&LcpFsm); /* FsmDown() results in a LcpLayerDown() if we're currently open. */ LcpLayerFinish(&LcpFsm); @@ -462,7 +457,7 @@ void LcpOpen(int open_mode) { LcpFsm.open_mode = open_mode; - LcpFailedMagic = 0; + LcpInfo.LcpFailedMagic = 0; FsmOpen(&LcpFsm); } @@ -472,7 +467,7 @@ LcpClose(struct fsm *fp) NewPhase(fp->physical, PHASE_TERMINATE); OsInterfaceDown(0); FsmClose(fp); - LcpFailedMagic = 0; + LcpInfo.LcpFailedMagic = 0; } /* @@ -697,17 +692,17 @@ LcpDecodeConfig(u_char *cp, int plen, int mode_type) /* Validate magic number */ if (magic == LcpInfo.want_magic) { LogPrintf(LogLCP, "Magic is same (%08lx) - %d times\n", - (u_long)magic, ++LcpFailedMagic); + (u_long)magic, ++LcpInfo.LcpFailedMagic); LcpInfo.want_magic = GenerateMagic(); memcpy(nakp, cp, 6); nakp += 6; - ualarm(TICKUNIT * (4 + 4 * LcpFailedMagic), 0); + ualarm(TICKUNIT * (4 + 4 * LcpInfo.LcpFailedMagic), 0); sigpause(0); } else { LcpInfo.his_magic = magic; memcpy(ackp, cp, length); ackp += length; - LcpFailedMagic = 0; + LcpInfo.LcpFailedMagic = 0; } } else { LcpInfo.my_reject |= (1 << type); diff --git a/usr.sbin/ppp/lcp.h b/usr.sbin/ppp/lcp.h index e9cda02831ca..b71a29b324b5 100644 --- a/usr.sbin/ppp/lcp.h +++ b/usr.sbin/ppp/lcp.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lcp.h,v 1.16 1998/01/11 17:50:38 brian Exp $ + * $Id: lcp.h,v 1.16.2.1 1998/01/29 00:49:25 brian Exp $ * * TODO: */ @@ -23,27 +23,30 @@ #define REJECTED(p, x) ((p)->his_reject & (1<<(x))) struct lcpstate { - u_int16_t his_mru; - u_int32_t his_accmap; - u_int32_t his_magic; - u_int32_t his_lqrperiod; - u_char his_protocomp; - u_char his_acfcomp; - u_short his_auth; + u_int16_t his_mru; /* Peers maximum packet size */ + u_int32_t his_accmap; /* Peeers async char control map */ + u_int32_t his_magic; /* Peers magic number */ + u_int32_t his_lqrperiod; /* Peers LQR frequency */ + int his_protocomp : 1; /* Does peer do Protocol field compression */ + int his_acfcomp : 1; /* Does peer do addr & cntrl fld compression */ + u_short his_auth; /* Peer wants this type of authentication */ - u_short want_mru; - u_int32_t want_accmap; - u_int32_t want_magic; - u_int32_t want_lqrperiod; - u_char want_protocomp; - u_char want_acfcomp; - u_short want_auth; + u_short want_mru; /* Our maximum packet size */ + u_int32_t want_accmap; /* Our async char control map */ + u_int32_t want_magic; /* Our magic number */ + u_int32_t want_lqrperiod; /* Our LQR frequency */ + int want_protocomp : 1; /* Do we do protocol field compression */ + int want_acfcomp : 1; /* Do we do addr & cntrl fld compression */ + u_short want_auth; /* We want this type of authentication */ u_int32_t his_reject; /* Request codes rejected by peer */ u_int32_t my_reject; /* Request codes I have rejected */ - u_short auth_iwait; - u_short auth_ineed; + u_short auth_iwait; /* I must authenticate to the peer */ + u_short auth_ineed; /* I require that the peer authenticates */ + + int LcpFailedMagic; /* Number of `magic is same' errors */ + struct pppTimer ReportTimer; /* Moan about hdlc errors every 60 seconds */ }; #define LCP_MAXCODE CODE_DISCREQ diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index 4c4390823cef..f0e226b336d3 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lqr.c,v 1.22 1998/01/21 02:15:19 brian Exp $ + * $Id: lqr.c,v 1.22.2.1 1998/01/29 00:49:25 brian Exp $ * * o LQR based on RFC1333 * @@ -198,7 +198,6 @@ LqrInput(struct physical *physical, struct mbuf * bp) void StartLqm(struct physical *physical) { - struct lcpstate *lcp = &LcpInfo; int period; lqrsendcnt = 0; /* start waiting all over for ECHOs */ @@ -211,12 +210,13 @@ StartLqm(struct physical *physical) StopTimer(&LqrTimer); LogPrintf(LogLQM, "LQM method = %d\n", lqmmethod); - if (lcp->his_lqrperiod || lcp->want_lqrperiod) { + if (LcpInfo.his_lqrperiod || LcpInfo.want_lqrperiod) { /* * We need to run timer. Let's figure out period. */ - period = lcp->his_lqrperiod ? lcp->his_lqrperiod : lcp->want_lqrperiod; + period = LcpInfo.his_lqrperiod ? + LcpInfo.his_lqrperiod : LcpInfo.want_lqrperiod; StopTimer(&LqrTimer); LqrTimer.state = TIMER_STOPPED; LqrTimer.load = period * SECTICKS / 100; diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 659595f70313..8ee21ce2dc2c 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -18,7 +18,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pap.c,v 1.20 1997/12/24 09:29:11 brian Exp $ + * $Id: pap.c,v 1.20.2.1 1998/01/29 00:49:27 brian Exp $ * * TODO: */ @@ -149,7 +149,6 @@ PapInput(struct mbuf * bp, struct physical *physical) { int len = plength(bp); struct fsmheader *php; - struct lcpstate *lcp = &LcpInfo; u_char *cp; if (len >= sizeof(struct fsmheader)) { @@ -164,8 +163,8 @@ PapInput(struct mbuf * bp, struct physical *physical) cp = (u_char *) (php + 1); if (PapValidate(cp, cp + *cp + 1, physical)) { SendPapCode(php->id, PAP_ACK, "Greetings!!", physical); - lcp->auth_ineed = 0; - if (lcp->auth_iwait == 0) { + LcpInfo.auth_ineed = 0; + if (LcpInfo.auth_iwait == 0) { if ((mode & MODE_DIRECT) && Physical_IsATTY(physical) && Enabled(ConfUtmp)) if (Utmp) @@ -196,9 +195,9 @@ PapInput(struct mbuf * bp, struct physical *physical) len = *cp++; cp[len] = 0; LogPrintf(LogPHASE, "Received PAP_ACK (%s)\n", cp); - if (lcp->auth_iwait == PROTO_PAP) { - lcp->auth_iwait = 0; - if (lcp->auth_ineed == 0) + if (LcpInfo.auth_iwait == PROTO_PAP) { + LcpInfo.auth_iwait = 0; + if (LcpInfo.auth_ineed == 0) NewPhase(physical, PHASE_NETWORK); } break; diff --git a/usr.sbin/ppp/phase.c b/usr.sbin/ppp/phase.c index 65128bf87576..1e9bde621be3 100644 --- a/usr.sbin/ppp/phase.c +++ b/usr.sbin/ppp/phase.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: phase.c,v 1.6.4.1 1998/01/29 00:49:28 brian Exp $ + * $Id: phase.c,v 1.6.4.2 1998/01/29 23:11:41 brian Exp $ */ #include @@ -34,9 +34,9 @@ #include "command.h" #include "mbuf.h" #include "log.h" +#include "timer.h" #include "lcp.h" #include "lcpproto.h" -#include "timer.h" #include "auth.h" #include "pap.h" #include "chap.h" @@ -73,21 +73,19 @@ Auth2Nam(u_short auth) void NewPhase(struct physical *physical, int new) { - struct lcpstate *lcp = &LcpInfo; - phase = new; LogPrintf(LogPHASE, "NewPhase: %s\n", PhaseNames[phase]); switch (phase) { case PHASE_AUTHENTICATE: - lcp->auth_ineed = lcp->want_auth; - lcp->auth_iwait = lcp->his_auth; - if (lcp->his_auth || lcp->want_auth) { + LcpInfo.auth_ineed = LcpInfo.want_auth; + LcpInfo.auth_iwait = LcpInfo.his_auth; + if (LcpInfo.his_auth || LcpInfo.want_auth) { LogPrintf(LogPHASE, " his = %s, mine = %s\n", - Auth2Nam(lcp->his_auth), Auth2Nam(lcp->want_auth)); + Auth2Nam(LcpInfo.his_auth), Auth2Nam(LcpInfo.want_auth)); /* XXX-ML AuthPapInfo and AuthChapInfo must be allocated! */ - if (lcp->his_auth == PROTO_PAP) + if (LcpInfo.his_auth == PROTO_PAP) StartAuthChallenge(&AuthPapInfo, physical); - if (lcp->want_auth == PROTO_CHAP) + if (LcpInfo.want_auth == PROTO_CHAP) StartAuthChallenge(&AuthChapInfo, physical); } else NewPhase(physical, PHASE_NETWORK);