From 82a4d4ec65a1e10b6a9bb79262167bf12585fbf2 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 16 Jun 2012 03:53:05 +0200 Subject: [PATCH] LCP global variables moved to ppp_pcb as well as input/output buffers --- src/netif/ppp/chap-new.c | 4 +- src/netif/ppp/eap.c | 34 ++++++++--------- src/netif/ppp/fsm.c | 6 +-- src/netif/ppp/lcp.c | 80 +++++++++++++++++++--------------------- src/netif/ppp/ppp.c | 14 ++----- src/netif/ppp/ppp.h | 30 ++++++++++++++- src/netif/ppp/upap.c | 8 ++-- 7 files changed, 95 insertions(+), 81 deletions(-) diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index 95cb870a..e60f2a34 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -329,7 +329,7 @@ static void chap_handle_response(ppp_pcb *pcb, int id, return; /* send the response */ - p = outpacket_buf; + p = pcb->outpacket_buf; MAKEHEADER(p, PPP_CHAP); mlen = strlen(pcb->chap_server.message); len = CHAP_HDRLEN + mlen; @@ -339,7 +339,7 @@ static void chap_handle_response(ppp_pcb *pcb, int id, p[3] = len; if (mlen > 0) memcpy(p + CHAP_HDRLEN, pcb->chap_server.message, mlen); - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + len); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + len); if (pcb->chap_server.flags & CHALLENGE_VALID) { pcb->chap_server.flags &= ~CHALLENGE_VALID; diff --git a/src/netif/ppp/eap.c b/src/netif/ppp/eap.c index e410074f..cb947f67 100644 --- a/src/netif/ppp/eap.c +++ b/src/netif/ppp/eap.c @@ -257,7 +257,7 @@ eap_state *esp; ppp_pcb *pcb = &ppp_pcb_list[pcb->eap.es_unit]; u_char *outp; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -266,7 +266,7 @@ eap_state *esp; PUTCHAR(pcb->eap.es_server.ea_id, outp); PUTSHORT(EAP_HEADERLEN, outp); - ppp_write(pcb, outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN); + ppp_write(pcb, pcb->outpacket_buf, EAP_HEADERLEN + PPP_HDRLEN); pcb->eap.es_server.ea_state = eapBadAuth; auth_peer_fail(pcb, PPP_EAP); @@ -283,7 +283,7 @@ eap_state *esp; ppp_pcb *pcb = &ppp_pcb_list[pcb->eap.es_unit]; u_char *outp; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -292,7 +292,7 @@ eap_state *esp; PUTCHAR(pcb->eap.es_server.ea_id, outp); PUTSHORT(EAP_HEADERLEN, outp); - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + EAP_HEADERLEN); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + EAP_HEADERLEN); auth_peer_success(pcb, PPP_EAP, 0, pcb->eap.es_server.ea_peer, pcb->eap.es_server.ea_peerlen); @@ -677,7 +677,7 @@ eap_state *esp; return; } - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -853,10 +853,10 @@ eap_state *esp; return; } - outlen = (outp - outpacket_buf) - PPP_HDRLEN; + outlen = (outp - pcb->outpacket_buf) - PPP_HDRLEN; PUTSHORT(outlen, lenloc); - ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, pcb->outpacket_buf, outlen + PPP_HDRLEN); pcb->eap.es_server.ea_requests++; @@ -1032,7 +1032,7 @@ static void eap_send_response(ppp_pcb *pcb, u_char id, u_char typenum, u_char *s u_char *outp; int msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -1046,7 +1046,7 @@ static void eap_send_response(ppp_pcb *pcb, u_char id, u_char typenum, u_char *s MEMCPY(outp, str, lenstr); } - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + msglen); } /* @@ -1056,7 +1056,7 @@ static void eap_chap_response(ppp_pcb *pcb, u_char id, u_char *hash, char *name, u_char *outp; int msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -1074,7 +1074,7 @@ static void eap_chap_response(ppp_pcb *pcb, u_char id, u_char *hash, char *name, MEMCPY(outp, name, namelen); } - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + msglen); } #ifdef USE_SRP @@ -1093,7 +1093,7 @@ int lenstr; u_char *outp; int msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -1108,7 +1108,7 @@ int lenstr; MEMCPY(outp, str, lenstr); } - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + msglen); } /* @@ -1125,7 +1125,7 @@ u_char *str; u_char *outp; int msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -1140,7 +1140,7 @@ u_char *str; PUTLONG(flags, outp); MEMCPY(outp, str, SHA_DIGESTSIZE); - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + msglen); } #endif /* USE_SRP */ @@ -1148,7 +1148,7 @@ static void eap_send_nak(ppp_pcb *pcb, u_char id, u_char type) { u_char *outp; int msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_EAP); @@ -1160,7 +1160,7 @@ static void eap_send_nak(ppp_pcb *pcb, u_char id, u_char type) { PUTCHAR(EAPT_NAK, outp); PUTCHAR(type, outp); - ppp_write(pcb, outpacket_buf, PPP_HDRLEN + msglen); + ppp_write(pcb, pcb->outpacket_buf, PPP_HDRLEN + msglen); } #ifdef USE_SRP diff --git a/src/netif/ppp/fsm.c b/src/netif/ppp/fsm.c index b022e312..fe5354c9 100644 --- a/src/netif/ppp/fsm.c +++ b/src/netif/ppp/fsm.c @@ -708,7 +708,7 @@ static void fsm_sconfreq(fsm *f, int retransmit) { /* * Make up the request packet */ - outp = outpacket_buf + PPP_HDRLEN + HEADERLEN; + outp = pcb->outpacket_buf + PPP_HDRLEN + HEADERLEN; if( f->callbacks->cilen && f->callbacks->addci ){ cilen = (*f->callbacks->cilen)(f); if( cilen > pcb->peer_mru - HEADERLEN ) @@ -738,7 +738,7 @@ void fsm_sdata(fsm *f, u_char code, u_char id, u_char *data, int datalen) { int outlen; /* Adjust length to be smaller than MTU */ - outp = outpacket_buf; + outp = pcb->outpacket_buf; if (datalen > pcb->peer_mru - HEADERLEN) datalen = pcb->peer_mru - HEADERLEN; if (datalen && data != outp + PPP_HDRLEN + HEADERLEN) @@ -748,7 +748,7 @@ void fsm_sdata(fsm *f, u_char code, u_char id, u_char *data, int datalen) { PUTCHAR(code, outp); PUTCHAR(id, outp); PUTSHORT(outlen, outp); - ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, pcb->outpacket_buf, outlen + PPP_HDRLEN); } #endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index c46ee2bb..70222747 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -80,15 +80,19 @@ int lcp_echo_interval = 0; /* Interval between LCP echo-requests */ int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */ #endif /* UNUSED */ +#if 0 /* UNUSED */ /* options */ static u_int lcp_echo_interval = LCP_ECHOINTERVAL; /* Interval between LCP echo-requests */ static u_int lcp_echo_fails = LCP_MAXECHOFAILS; /* Tolerance to unanswered echo-requests */ +#endif /* UNUSED */ +#if 0 /* UNUSED */ #if PPP_LCP_ADAPTIVE bool lcp_echo_adaptive = 0; /* request echo only if the link was idle */ #endif bool lax_recv = 0; /* accept control chars in asyncmap */ bool noendpoint = 0; /* don't send/accept endpoint discriminator */ +#endif /* UNUSED */ #if PPP_OPTIONS static int noopt (char **); @@ -208,18 +212,6 @@ static option_t lcp_option_list[] = { }; #endif /* PPP_OPTIONS */ -/* global vars */ -#if PPPOS_SUPPORT -ext_accm xmit_accm[NUM_PPP]; /* extended transmit ACCM */ -#endif /* PPPOS_SUPPORT */ - -static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */ -static int lcp_echo_number = 0; /* ID number of next echo frame */ -static int lcp_echo_timer_running = 0; /* set if a timer is running */ - -/* FIXME: do we really need such a large buffer? The typical 1500 bytes seem too much. */ -static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */ - /* * Callbacks for fsm code. (CI = Configuration Information) */ @@ -308,8 +300,6 @@ struct protent lcp_protent = { #endif /* DEMAND_SUPPORT */ }; -int lcp_loopbackfail = DEFLOOPBACKFAIL; - /* * Length of each type of configuration option (in octets) */ @@ -492,7 +482,7 @@ void lcp_lowerup(ppp_pcb *pcb) { ppp_set_xaccm(pcb, &xmit_accm[pcb->unit]); #endif /* PPPOS_SUPPORT */ if (ppp_send_config(pcb, PPP_MRU, 0xffffffff, 0, 0) < 0 - || ppp_recv_config(pcb, PPP_MRU, (lax_recv? 0: 0xffffffff), + || ppp_recv_config(pcb, PPP_MRU, (pcb->settings.lax_recv? 0: 0xffffffff), wo->neg_pcompression, wo->neg_accompression) < 0) return; pcb->peer_mru = PPP_MRU; @@ -705,7 +695,7 @@ static void lcp_resetci(fsm *f) { #ifdef HAVE_MULTILINK } #endif /* HAVE_MULTILINK */ - if (noendpoint) + if (pcb->settings.noendpoint) ao->neg_endpoint = 0; pcb->peer_mru = PPP_MRU; auth_reset(pcb); @@ -1492,7 +1482,7 @@ static int lcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { */ if (f->state != OPENED) { if (looped_back) { - if (++try.numloops >= lcp_loopbackfail) { + if (++try.numloops >= pcb->lcp_loopbackfail) { notice("Serial line is looped back."); pcb->status = EXIT_LOOPBACK; lcp_close(f->pcb, "Loopback detected"); @@ -1773,7 +1763,7 @@ static int lcp_reqci(fsm *f, u_char *inp, int *lenp, int reject_if_disagree) { * Process all his options. */ next = inp; - nakp = nak_buffer; + nakp = pcb->nak_buffer; rejp = inp; while (l) { orc = CONFACK; /* Assume success */ @@ -2190,8 +2180,8 @@ endswitch: /* * Copy the Nak'd options from the nak_buffer to the caller's buffer. */ - *lenp = nakp - nak_buffer; - MEMCPY(inp, nak_buffer, *lenp); + *lenp = nakp - pcb->nak_buffer; + MEMCPY(inp, pcb->nak_buffer, *lenp); break; case CONFREJ: *lenp = rejp - inp; @@ -2238,7 +2228,7 @@ static void lcp_up(fsm *f) { (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), ho->neg_pcompression, ho->neg_accompression); ppp_recv_config(pcb, mru, - (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff), + (pcb->settings.lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff), go->neg_pcompression, go->neg_accompression); if (ho->neg_mru) @@ -2550,12 +2540,12 @@ static int lcp_printpkt(u_char *p, int plen, */ static void LcpLinkFailure(fsm *f) { - ppp_pcb *pc = f->pcb; + ppp_pcb *pcb = f->pcb; if (f->state == OPENED) { - info("No response to %d echo-requests", lcp_echos_pending); + info("No response to %d echo-requests", pcb->lcp_echos_pending); notice("Serial link appears to be disconnected."); - pc->status = EXIT_PEER_DEAD; - lcp_close(f->pcb, "Peer not responding"); + pcb->status = EXIT_PEER_DEAD; + lcp_close(pcb, "Peer not responding"); } } @@ -2564,6 +2554,8 @@ static void LcpLinkFailure(fsm *f) { */ static void LcpEchoCheck(fsm *f) { + ppp_pcb *pcb = f->pcb; + LcpSendEchoRequest (f); if (f->state != OPENED) return; @@ -2571,10 +2563,10 @@ static void LcpEchoCheck(fsm *f) { /* * Start the timer for the next interval. */ - if (lcp_echo_timer_running) + if (pcb->lcp_echo_timer_running) warn("assertion lcp_echo_timer_running==0 failed"); - TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval); - lcp_echo_timer_running = 1; + TIMEOUT (LcpEchoTimeout, f, pcb->settings.lcp_echo_interval); + pcb->lcp_echo_timer_running = 1; } /* @@ -2582,8 +2574,10 @@ static void LcpEchoCheck(fsm *f) { */ static void LcpEchoTimeout(void *arg) { - if (lcp_echo_timer_running != 0) { - lcp_echo_timer_running = 0; + fsm *f = (fsm*)f; + ppp_pcb *pcb = f->pcb; + if (pcb->lcp_echo_timer_running != 0) { + pcb->lcp_echo_timer_running = 0; LcpEchoCheck ((fsm *) arg); } } @@ -2610,7 +2604,7 @@ static void lcp_received_echo_reply(fsm *f, int id, u_char *inp, int len) { } /* Reset the number of outstanding echo frames */ - lcp_echos_pending = 0; + pcb->lcp_echos_pending = 0; } /* @@ -2626,10 +2620,10 @@ static void LcpSendEchoRequest(fsm *f) { /* * Detect the failure of the peer at this point. */ - if (lcp_echo_fails != 0) { - if (lcp_echos_pending >= lcp_echo_fails) { + if (pcb->settings.lcp_echo_fails != 0) { + if (pcb->lcp_echos_pending >= pcb->settings.lcp_echo_fails) { LcpLinkFailure(f); - lcp_echos_pending = 0; + pcb->lcp_echos_pending = 0; } } @@ -2638,7 +2632,7 @@ static void LcpSendEchoRequest(fsm *f) { * If adaptive echos have been enabled, only send the echo request if * no traffic was received since the last one. */ - if (lcp_echo_adaptive) { + if (pcb->settings.lcp_echo_adaptive) { static unsigned int last_pkts_in = 0; #if PPP_STATS_SUPPORT @@ -2660,8 +2654,8 @@ static void LcpSendEchoRequest(fsm *f) { lcp_magic = go->magicnumber; pktp = pkt; PUTLONG(lcp_magic, pktp); - fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt); - ++lcp_echos_pending; + fsm_sdata(f, ECHOREQ, pcb->lcp_echo_number++ & 0xFF, pkt, pktp - pkt); + ++pcb->lcp_echos_pending; } } @@ -2673,12 +2667,12 @@ static void lcp_echo_lowerup(ppp_pcb *pcb) { fsm *f = &pcb->lcp_fsm; /* Clear the parameters for generating echo frames */ - lcp_echos_pending = 0; - lcp_echo_number = 0; - lcp_echo_timer_running = 0; + pcb->lcp_echos_pending = 0; + pcb->lcp_echo_number = 0; + pcb->lcp_echo_timer_running = 0; /* If a timeout interval is specified then start the timer */ - if (lcp_echo_interval != 0) + if (pcb->settings.lcp_echo_interval != 0) LcpEchoCheck (f); } @@ -2689,9 +2683,9 @@ static void lcp_echo_lowerup(ppp_pcb *pcb) { static void lcp_echo_lowerdown(ppp_pcb *pcb) { fsm *f = &pcb->lcp_fsm; - if (lcp_echo_timer_running != 0) { + if (pcb->lcp_echo_timer_running != 0) { UNTIMEOUT (LcpEchoTimeout, f); - lcp_echo_timer_running = 0; + pcb->lcp_echo_timer_running = 0; } } diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 8369e8cc..bb7bd0be 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -126,17 +126,6 @@ /*** LOCAL DEFINITIONS ***/ /*************************/ -/* - * Buffers for outgoing packets. This must be accessed only from the appropriate - * PPP task so that it doesn't need to be protected to avoid collisions. - */ -/* FIXME: outpacket_buf per PPP session */ -u_char outpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for outgoing packet */ - -#if PPPOS_SUPPORT -u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */ -#endif /* PPPOS_SUPPORT */ - /* FIXME: add stats per PPP session */ #if PPP_STATS_SUPPORT static struct timeval start_time; /* Time when link was started. */ @@ -253,6 +242,7 @@ ppp_pcb *ppp_new(void) { pcb->unit = pd; pcb->open_flag = 1; pcb->status = EXIT_OK; + pcb->lcp_loopbackfail = DEFLOOPBACKFAIL; new_phase(pcb, PHASE_INITIALIZE); /* default configuration */ @@ -262,6 +252,8 @@ ppp_pcb *ppp_new(void) { pcb->settings.chap_timeout_time = 3; pcb->settings.chap_max_transmits = 10; #endif /* CHAP_SUPPPORT */ + pcb->settings.lcp_echo_interval = LCP_ECHOINTERVAL; + pcb->settings.lcp_echo_fails = LCP_MAXECHOFAILS; /* * Initialize each protocol. diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index 94b8e86e..49d87851 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -178,6 +178,15 @@ typedef struct ppp_settings_s { int chap_max_transmits; int chap_rechallenge_time; #endif /* CHAP_SUPPPORT */ + + u_int lcp_echo_interval; /* Interval between LCP echo-requests */ + u_int lcp_echo_fails; /* Tolerance to unanswered echo-requests */ +#if PPP_LCP_ADAPTIVE + bool lcp_echo_adaptive; /* request echo only if the link was idle */ +#endif + bool lax_recv; /* accept control chars in asyncmap */ + bool noendpoint; /* don't send/accept endpoint discriminator */ + } ppp_settings; struct ppp_addrs { @@ -450,8 +459,17 @@ typedef struct ppp_pcb_s { lcp_options lcp_gotoptions; /* Options that peer ack'd */ lcp_options lcp_allowoptions; /* Options we allow peer to request */ lcp_options lcp_hisoptions; /* Options that we ack'd */ +#if PPPOS_SUPPORT + ext_accm xmit_accm; /* extended transmit ACCM */ +#endif /* PPPOS_SUPPORT */ + int lcp_echos_pending; /* Number of outstanding echo msgs */ + int lcp_echo_number; /* ID number of next echo frame */ + int lcp_echo_timer_running; /* set if a timer is running */ + /* FIXME: do we really need such a large buffer? The typical 1500 bytes seem too much. */ + u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */ + int lcp_loopbackfail; - fsm ipcp_fsm; /* IPCP fsm structure */ + fsm ipcp_fsm; /* IPCP fsm structure */ ipcp_options ipcp_wantoptions; /* Options that we want to request */ ipcp_options ipcp_gotoptions; /* Options that peer ack'd */ ipcp_options ipcp_allowoptions; /* Options we allow peer to request */ @@ -462,6 +480,16 @@ typedef struct ppp_pcb_s { int ipcp_is_up; /* have called np_up() */ bool ask_for_local; /* request our address from peer */ + /* + * Buffers for outgoing packets. This must be accessed only from the appropriate + * PPP task so that it doesn't need to be protected to avoid collisions. + */ + u_char outpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for outgoing packet */ + +#if PPPOS_SUPPORT + u_char inpacket_buf[PPP_MRU+PPP_HDRLEN]; /* buffer for incoming packet */ +#endif /* PPPOS_SUPPORT */ + } ppp_pcb; /************************ diff --git a/src/netif/ppp/upap.c b/src/netif/ppp/upap.c index 400e8d27..f72ccd62 100644 --- a/src/netif/ppp/upap.c +++ b/src/netif/ppp/upap.c @@ -525,7 +525,7 @@ static void upap_sauthreq(ppp_pcb *pcb) { outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) + pcb->upap.us_userlen + pcb->upap.us_passwdlen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_PAP); @@ -538,7 +538,7 @@ static void upap_sauthreq(ppp_pcb *pcb) { PUTCHAR(pcb->upap.us_passwdlen, outp); MEMCPY(outp, pcb->upap.us_passwd, pcb->upap.us_passwdlen); - ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, pcb->outpacket_buf, outlen + PPP_HDRLEN); TIMEOUT(upap_timeout, pcb, pcb->upap.us_timeouttime); ++pcb->upap.us_transmits; @@ -554,7 +554,7 @@ static void upap_sresp(ppp_pcb *pcb, u_char code, u_char id, char *msg, int msgl int outlen; outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen; - outp = outpacket_buf; + outp = pcb->outpacket_buf; MAKEHEADER(outp, PPP_PAP); PUTCHAR(code, outp); @@ -562,7 +562,7 @@ static void upap_sresp(ppp_pcb *pcb, u_char code, u_char id, char *msg, int msgl PUTSHORT(outlen, outp); PUTCHAR(msglen, outp); MEMCPY(outp, msg, msglen); - ppp_write(pcb, outpacket_buf, outlen + PPP_HDRLEN); + ppp_write(pcb, pcb->outpacket_buf, outlen + PPP_HDRLEN); } #endif /* UNUSED */