From b714cd5f4b15ffe56c50903b222535fea9ed657f Mon Sep 17 00:00:00 2001 From: fbernon Date: Thu, 29 Nov 2007 22:19:56 +0000 Subject: [PATCH] First fix for bug #21664 "PPP code is broken". --- src/netif/ppp/auth.c | 83 ++++++----- src/netif/ppp/auth.h | 1 - src/netif/ppp/chap.c | 15 +- src/netif/ppp/chap.h | 3 +- src/netif/ppp/chpms.c | 10 +- src/netif/ppp/fsm.c | 315 +++++++++++++++++++++------------------ src/netif/ppp/fsm.h | 29 ++-- src/netif/ppp/ipcp.c | 31 ++-- src/netif/ppp/ipcp.h | 4 +- src/netif/ppp/lcp.c | 41 ++--- src/netif/ppp/lcp.h | 4 +- src/netif/ppp/md5.c | 12 +- src/netif/ppp/pap.c | 15 +- src/netif/ppp/pap.h | 3 +- src/netif/ppp/ppp.c | 184 ++++++++++++----------- src/netif/ppp/ppp.h | 10 +- src/netif/ppp/ppp_oe.c | 18 ++- src/netif/ppp/pppdebug.h | 6 +- src/netif/ppp/randm.c | 13 +- src/netif/ppp/randm.h | 4 +- src/netif/ppp/vj.c | 17 ++- src/netif/ppp/vjbsdhdr.h | 1 - 22 files changed, 438 insertions(+), 381 deletions(-) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 640cc457..95f64a7f 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -64,8 +64,13 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#if PPP_SUPPORT > 0 +#include "pppdebug.h" + #include "fsm.h" #include "lcp.h" #include "pap.h" @@ -73,12 +78,9 @@ #include "auth.h" #include "ipcp.h" -#if CBCP_SUPPORT > 0 +#if CBCP_SUPPORT #include "cbcp.h" -#endif - -#include "pppdebug.h" - +#endif /* CBCP_SUPPORT */ /*************************/ /*** LOCAL DEFINITIONS ***/ @@ -122,13 +124,13 @@ static int get_pap_passwd (int, char *, char *); static int have_pap_secret (void); static int have_chap_secret (char *, char *, u32_t); static int ip_addr_check (u32_t, struct wordlist *); -#if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 */ +#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */ static void set_allowed_addrs(int unit, struct wordlist *addrs); static void free_wordlist (struct wordlist *); -#endif -#if CBCP_SUPPORT > 0 +#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */ +#if CBCP_SUPPORT static void callback_phase (int); -#endif +#endif /* CBCP_SUPPORT */ /******************************/ @@ -139,10 +141,10 @@ static void callback_phase (int); /*****************************/ /*** LOCAL DATA STRUCTURES ***/ /*****************************/ -#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 +#if PAP_SUPPORT || CHAP_SUPPORT /* The name by which the peer authenticated itself to us. */ static char peer_authname[MAXNAMELEN]; -#endif +#endif /* PAP_SUPPORT || CHAP_SUPPORT */ /* Records which authentication operations haven't completed yet. */ static int auth_pending[NUM_PPP]; @@ -162,10 +164,10 @@ static int num_np_open; /* Number of network protocols which have come up. */ static int num_np_up; -#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 +#if PAP_SUPPORT || CHAP_SUPPORT /* Set if we got the contents of passwd[] from the pap-secrets file. */ static int passwd_from_file; -#endif +#endif /* PAP_SUPPORT || CHAP_SUPPORT */ @@ -237,9 +239,9 @@ void link_established(int unit) struct protent *protp; lcp_options *wo = &lcp_wantoptions[unit]; lcp_options *go = &lcp_gotoptions[unit]; -#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 +#if PAP_SUPPORT || CHAP_SUPPORT lcp_options *ho = &lcp_hisoptions[unit]; -#endif +#endif /* PAP_SUPPORT || CHAP_SUPPORT */ AUTHDEBUG((LOG_INFO, "link_established: %d\n", unit)); /* @@ -265,31 +267,31 @@ void link_established(int unit) lcp_phase[unit] = PHASE_AUTHENTICATE; auth = 0; -#if CHAP_SUPPORT > 0 +#if CHAP_SUPPORT if (go->neg_chap) { ChapAuthPeer(unit, ppp_settings.our_name, go->chap_mdtype); auth |= CHAP_PEER; } -#endif -#if PAP_SUPPORT > 0 && CHAP_SUPPORT > 0 +#endif /* CHAP_SUPPORT */ +#if PAP_SUPPORT && CHAP_SUPPORT else -#endif -#if PAP_SUPPORT > 0 +#endif /* PAP_SUPPORT && CHAP_SUPPORT */ +#if PAP_SUPPORT if (go->neg_upap) { upap_authpeer(unit); auth |= PAP_PEER; } -#endif -#if CHAP_SUPPORT > 0 +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT if (ho->neg_chap) { ChapAuthWithPeer(unit, ppp_settings.user, ho->chap_mdtype); auth |= CHAP_WITHPEER; } -#endif -#if PAP_SUPPORT > 0 && CHAP_SUPPORT > 0 +#endif /* CHAP_SUPPORT */ +#if PAP_SUPPORT && CHAP_SUPPORT else -#endif -#if PAP_SUPPORT > 0 +#endif /* PAP_SUPPORT && CHAP_SUPPORT */ +#if PAP_SUPPORT if (ho->neg_upap) { if (ppp_settings.passwd[0] == 0) { passwd_from_file = 1; @@ -299,7 +301,7 @@ void link_established(int unit) upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd); auth |= PAP_WITHPEER; } -#endif +#endif /* PAP_SUPPORT */ auth_pending[unit] = auth; if (!auth) @@ -320,7 +322,7 @@ void auth_peer_fail(int unit, u16_t protocol) } -#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 +#if PAP_SUPPORT || CHAP_SUPPORT /* * The peer has been successfully authenticated using `protocol'. */ @@ -412,7 +414,7 @@ void auth_withpeer_success(int unit, u16_t protocol) if ((auth_pending[unit] &= ~pbit) == 0) network_phase(unit); } -#endif +#endif /* PAP_SUPPORT || CHAP_SUPPORT */ /* @@ -487,8 +489,7 @@ void auth_reset(int unit) } } - -#if PAP_SUPPORT > 0 +#if PAP_SUPPORT /* * check_passwd - Check the user name and passwd against the PAP secrets * file. If requested, also check against the system password database, @@ -564,7 +565,7 @@ int check_passwd( return ret; #endif } -#endif +#endif /* PAP_SUPPORT */ /* @@ -589,7 +590,7 @@ int bad_ip_adrs(u32_t addr) } -#if CHAP_SUPPORT > 0 +#if CHAP_SUPPORT /* * get_secret - open the CHAP secret file and return the secret * for authenticating the given client on the given server. @@ -650,7 +651,7 @@ int get_secret( return 1; #endif } -#endif +#endif /* CHAP_SUPPORT */ #if 0 /* UNUSED */ @@ -713,7 +714,7 @@ static void network_phase(int unit) did_authup = 1; } -#if CBCP_SUPPORT > 0 +#if CBCP_SUPPORT /* * If we negotiated callback, do it now. */ @@ -722,7 +723,7 @@ static void network_phase(int unit) (*cbcp_protent.open)(unit); return; } -#endif +#endif /* CBCP_SUPPORT */ lcp_phase[unit] = PHASE_NETWORK; for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) @@ -858,7 +859,7 @@ static int have_chap_secret(char *client, char *server, u32_t remote) } -#if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 */ +#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */ /* * set_allowed_addrs() - set the list of allowed addresses. */ @@ -892,7 +893,7 @@ static void set_allowed_addrs(int unit, struct wordlist *addrs) } #endif } -#endif +#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */ static int ip_addr_check(u32_t addr, struct wordlist *addrs) { @@ -908,7 +909,7 @@ static int ip_addr_check(u32_t addr, struct wordlist *addrs) return 1; } -#if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT */ +#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */ /* * free_wordlist - release memory allocated for a wordlist. */ @@ -922,6 +923,6 @@ static void free_wordlist(struct wordlist *wp) wp = next; } } -#endif +#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */ #endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/auth.h b/src/netif/ppp/auth.h index d6a5de5b..0cf662f9 100644 --- a/src/netif/ppp/auth.h +++ b/src/netif/ppp/auth.h @@ -90,5 +90,4 @@ int auth_ip_addr (int, u32_t); /* check if IP address is unreasonable */ int bad_ip_adrs (u32_t); - #endif /* AUTH_H */ diff --git a/src/netif/ppp/chap.c b/src/netif/ppp/chap.c index 53dbeae0..ce2bfe0c 100644 --- a/src/netif/ppp/chap.c +++ b/src/netif/ppp/chap.c @@ -66,18 +66,21 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#if CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#if PPP_SUPPORT > 0 +#include "pppdebug.h" + #include "magic.h" - -#if CHAP_SUPPORT > 0 - #include "randm.h" #include "auth.h" #include "md5.h" #include "chap.h" #include "chpms.h" -#include "pppdebug.h" /*************************/ @@ -865,6 +868,6 @@ static int ChapPrintPkt( } #endif -#endif /* CHAP_SUPPORT > 0 */ +#endif /* CHAP_SUPPORT */ #endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/chap.h b/src/netif/ppp/chap.h index 6fd97275..659b343b 100644 --- a/src/netif/ppp/chap.h +++ b/src/netif/ppp/chap.h @@ -62,7 +62,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: chap.h,v 1.1 2003/05/27 14:37:56 jani Exp $ + * $Id: chap.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $ */ #ifndef CHAP_H @@ -164,4 +164,3 @@ void ChapAuthWithPeer (int, char *, int); void ChapAuthPeer (int, char *, int); #endif /* CHAP_H */ - diff --git a/src/netif/ppp/chpms.c b/src/netif/ppp/chpms.c index 01755ba3..df4dca0d 100644 --- a/src/netif/ppp/chpms.c +++ b/src/netif/ppp/chpms.c @@ -66,10 +66,14 @@ #define USE_CRYPT +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#if MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ #include "ppp.h" - -#if MSCHAP_SUPPORT > 0 +#include "pppdebug.h" #include "md4.h" #ifndef USE_CRYPT @@ -77,7 +81,6 @@ #endif #include "chap.h" #include "chpms.h" -#include "pppdebug.h" /*************************/ @@ -396,3 +399,4 @@ static ChapMS_LANMan( #endif /* MSCHAP_SUPPORT */ +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/fsm.c b/src/netif/ppp/fsm.c index 6f08c800..cb708126 100644 --- a/src/netif/ppp/fsm.c +++ b/src/netif/ppp/fsm.c @@ -49,23 +49,42 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ - /* * TODO: * Randomize fsm id on link/init. * Deal with variable outgoing MTU. */ +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#if PPP_SUPPORT > 0 -#include "fsm.h" #include "pppdebug.h" +#include "fsm.h" + /*************************/ /*** LOCAL DEFINITIONS ***/ /*************************/ +#if PPP_DEBUG + +static const char *ppperr_strerr[] = { + "LS_INITIAL", /* LS_INITIAL 0 */ + "LS_STARTING", /* LS_STARTING 1 */ + "LS_CLOSED", /* LS_CLOSED 2 */ + "LS_STOPPED", /* LS_STOPPED 3 */ + "LS_CLOSING", /* LS_CLOSING 4 */ + "LS_STOPPING", /* LS_STOPPING 5 */ + "LS_REQSENT", /* LS_REQSENT 6 */ + "LS_ACKRCVD", /* LS_ACKRCVD 7 */ + "LS_ACKSENT", /* LS_ACKSENT 8 */ + "LS_OPENED" /* LS_OPENED 9 */ +}; + +#endif /* PPP_DEBUG */ /************************/ /*** LOCAL DATA TYPES ***/ @@ -109,7 +128,7 @@ int peer_mru[NUM_PPP]; */ void fsm_init(fsm *f) { - f->state = INITIAL; + f->state = LS_INITIAL; f->flags = 0; f->id = 0; /* XXX Start with random id? */ f->timeouttime = FSM_DEFTIMEOUT; @@ -128,27 +147,27 @@ void fsm_lowerup(fsm *f) int oldState = f->state; switch( f->state ){ - case INITIAL: - f->state = CLOSED; + case LS_INITIAL: + f->state = LS_CLOSED; break; - case STARTING: + case LS_STARTING: if( f->flags & OPT_SILENT ) - f->state = STOPPED; + f->state = LS_STOPPED; else { /* Send an initial configure-request */ fsm_sconfreq(f, 0); - f->state = REQSENT; + f->state = LS_REQSENT; } break; default: - FSMDEBUG((LOG_INFO, "%s: Up event in state %d!\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "%s: Up event in state %d (%s)!\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); } - FSMDEBUG((LOG_INFO, "%s: lowerup state %d -> %d\n", - PROTO_NAME(f), oldState, f->state)); + FSMDEBUG((LOG_INFO, "%s: lowerup state %d (%s) -> %d (%s)\n", + PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state])); } @@ -162,42 +181,42 @@ void fsm_lowerdown(fsm *f) int oldState = f->state; switch( f->state ){ - case CLOSED: - f->state = INITIAL; + case LS_CLOSED: + f->state = LS_INITIAL; break; - case STOPPED: - f->state = STARTING; + case LS_STOPPED: + f->state = LS_STARTING; if( f->callbacks->starting ) (*f->callbacks->starting)(f); break; - case CLOSING: - f->state = INITIAL; + case LS_CLOSING: + f->state = LS_INITIAL; UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ break; - case STOPPING: - case REQSENT: - case ACKRCVD: - case ACKSENT: - f->state = STARTING; + case LS_STOPPING: + case LS_REQSENT: + case LS_ACKRCVD: + case LS_ACKSENT: + f->state = LS_STARTING; UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ break; - case OPENED: + case LS_OPENED: if( f->callbacks->down ) (*f->callbacks->down)(f); - f->state = STARTING; + f->state = LS_STARTING; break; default: - FSMDEBUG((LOG_INFO, "%s: Down event in state %d!\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "%s: Down event in state %d (%s)!\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); } - FSMDEBUG((LOG_INFO, "%s: lowerdown state %d -> %d\n", - PROTO_NAME(f), oldState, f->state)); + FSMDEBUG((LOG_INFO, "%s: lowerdown state %d (%s) -> %d (%s)\n", + PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state])); } @@ -209,27 +228,27 @@ void fsm_open(fsm *f) int oldState = f->state; switch( f->state ){ - case INITIAL: - f->state = STARTING; + case LS_INITIAL: + f->state = LS_STARTING; if( f->callbacks->starting ) (*f->callbacks->starting)(f); break; - case CLOSED: + case LS_CLOSED: if( f->flags & OPT_SILENT ) - f->state = STOPPED; + f->state = LS_STOPPED; else { /* Send an initial configure-request */ fsm_sconfreq(f, 0); - f->state = REQSENT; + f->state = LS_REQSENT; } break; - case CLOSING: - f->state = STOPPING; + case LS_CLOSING: + f->state = LS_STOPPING; /* fall through */ - case STOPPED: - case OPENED: + case LS_STOPPED: + case LS_OPENED: if( f->flags & OPT_RESTART ){ fsm_lowerdown(f); fsm_lowerup(f); @@ -237,8 +256,8 @@ void fsm_open(fsm *f) break; } - FSMDEBUG((LOG_INFO, "%s: open state %d -> %d\n", - PROTO_NAME(f), oldState, f->state)); + FSMDEBUG((LOG_INFO, "%s: open state %d (%s) -> %d (%s)\n", + PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state])); } @@ -246,7 +265,7 @@ void fsm_open(fsm *f) * fsm_close - Start closing connection. * * Cancel timeouts and either initiate close or possibly go directly to - * the CLOSED state. + * the LS_CLOSED state. */ void fsm_close(fsm *f, char *reason) { @@ -255,21 +274,21 @@ void fsm_close(fsm *f, char *reason) f->term_reason = reason; f->term_reason_len = (reason == NULL? 0: strlen(reason)); switch( f->state ){ - case STARTING: - f->state = INITIAL; + case LS_STARTING: + f->state = LS_INITIAL; break; - case STOPPED: - f->state = CLOSED; + case LS_STOPPED: + f->state = LS_CLOSED; break; - case STOPPING: - f->state = CLOSING; + case LS_STOPPING: + f->state = LS_CLOSING; break; - case REQSENT: - case ACKRCVD: - case ACKSENT: - case OPENED: - if( f->state != OPENED ) + case LS_REQSENT: + case LS_ACKRCVD: + case LS_ACKSENT: + case LS_OPENED: + if( f->state != LS_OPENED ) UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ else if( f->callbacks->down ) (*f->callbacks->down)(f); /* Inform upper layers we're down */ @@ -281,12 +300,12 @@ void fsm_close(fsm *f, char *reason) TIMEOUT(fsm_timeout, f, f->timeouttime); --f->retransmits; - f->state = CLOSING; + f->state = LS_CLOSING; break; } - FSMDEBUG((LOG_INFO, "%s: close reason=%s state %d -> %d\n", - PROTO_NAME(f), reason, oldState, f->state)); + FSMDEBUG((LOG_INFO, "%s: close reason=%s state %d (%s) -> %d (%s)\n", + PROTO_NAME(f), reason, oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state])); } @@ -356,9 +375,9 @@ void fsm_input(fsm *f, u_char *inpacket, int l) } len -= HEADERLEN; /* subtract header length */ - if( f->state == INITIAL || f->state == STARTING ){ - FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd packet in state %d.\n", - f->protocol, f->state)); + if( f->state == LS_INITIAL || f->state == LS_STARTING ){ + FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd packet in state %d (%s).\n", + f->protocol, f->state, ppperr_strerr[f->state])); return; } FSMDEBUG((LOG_INFO, "fsm_input(%s):%d,%d,%d\n", PROTO_NAME(f), code, id, l)); @@ -408,28 +427,28 @@ void fsm_input(fsm *f, u_char *inpacket, int l) void fsm_protreject(fsm *f) { switch( f->state ){ - case CLOSING: + case LS_CLOSING: UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ /* fall through */ - case CLOSED: - f->state = CLOSED; + case LS_CLOSED: + f->state = LS_CLOSED; if( f->callbacks->finished ) (*f->callbacks->finished)(f); break; - case STOPPING: - case REQSENT: - case ACKRCVD: - case ACKSENT: + case LS_STOPPING: + case LS_REQSENT: + case LS_ACKRCVD: + case LS_ACKSENT: UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ /* fall through */ - case STOPPED: - f->state = STOPPED; + case LS_STOPPED: + f->state = LS_STOPPED; if( f->callbacks->finished ) (*f->callbacks->finished)(f); break; - case OPENED: + case LS_OPENED: if( f->callbacks->down ) (*f->callbacks->down)(f); @@ -440,12 +459,12 @@ void fsm_protreject(fsm *f) TIMEOUT(fsm_timeout, f, f->timeouttime); --f->retransmits; - f->state = STOPPING; + f->state = LS_STOPPING; break; default: - FSMDEBUG((LOG_INFO, "%s: Protocol-reject event in state %d!\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "%s: Protocol-reject event in state %d (%s)!\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); } } @@ -465,20 +484,20 @@ static void fsm_timeout(void *arg) fsm *f = (fsm *) arg; switch (f->state) { - case CLOSING: - case STOPPING: + case LS_CLOSING: + case LS_STOPPING: if( f->retransmits <= 0 ){ - FSMDEBUG((LOG_WARNING, "%s: timeout sending Terminate-Request state=%d\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_WARNING, "%s: timeout sending Terminate-Request state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); /* * We've waited for an ack long enough. Peer probably heard us. */ - f->state = (f->state == CLOSING)? CLOSED: STOPPED; + f->state = (f->state == LS_CLOSING)? LS_CLOSED: LS_STOPPED; if( f->callbacks->finished ) (*f->callbacks->finished)(f); } else { - FSMDEBUG((LOG_WARNING, "%s: timeout resending Terminate-Requests state=%d\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_WARNING, "%s: timeout resending Terminate-Requests state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); /* Send Terminate-Request */ fsm_sdata(f, TERMREQ, f->reqid = ++f->id, (u_char *) f->term_reason, f->term_reason_len); @@ -487,31 +506,31 @@ static void fsm_timeout(void *arg) } break; - case REQSENT: - case ACKRCVD: - case ACKSENT: + case LS_REQSENT: + case LS_ACKRCVD: + case LS_ACKSENT: if (f->retransmits <= 0) { - FSMDEBUG((LOG_WARNING, "%s: timeout sending Config-Requests state=%d\n", - PROTO_NAME(f), f->state)); - f->state = STOPPED; + FSMDEBUG((LOG_WARNING, "%s: timeout sending Config-Requests state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); + f->state = LS_STOPPED; if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished ) (*f->callbacks->finished)(f); } else { - FSMDEBUG((LOG_WARNING, "%s: timeout resending Config-Request state=%d\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_WARNING, "%s: timeout resending Config-Request state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); /* Retransmit the configure-request */ if (f->callbacks->retransmit) (*f->callbacks->retransmit)(f); fsm_sconfreq(f, 1); /* Re-send Configure-Request */ - if( f->state == ACKRCVD ) - f->state = REQSENT; + if( f->state == LS_ACKRCVD ) + f->state = LS_REQSENT; } break; default: - FSMDEBUG((LOG_INFO, "%s: Timeout event in state %d!\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "%s: Timeout event in state %d (%s)!\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); } } @@ -523,28 +542,28 @@ static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len) { int code, reject_if_disagree; - FSMDEBUG((LOG_INFO, "fsm_rconfreq(%s): Rcvd id %d state=%d\n", - PROTO_NAME(f), id, f->state)); + FSMDEBUG((LOG_INFO, "fsm_rconfreq(%s): Rcvd id %d state=%d (%s)\n", + PROTO_NAME(f), id, f->state, ppperr_strerr[f->state])); switch( f->state ){ - case CLOSED: + case LS_CLOSED: /* Go away, we're closed */ fsm_sdata(f, TERMACK, id, NULL, 0); return; - case CLOSING: - case STOPPING: + case LS_CLOSING: + case LS_STOPPING: return; - case OPENED: + case LS_OPENED: /* Go down and restart negotiation */ if( f->callbacks->down ) (*f->callbacks->down)(f); /* Inform upper layers */ fsm_sconfreq(f, 0); /* Send initial Configure-Request */ break; - case STOPPED: + case LS_STOPPED: /* Negotiation started by our peer */ fsm_sconfreq(f, 0); /* Send initial Configure-Request */ - f->state = REQSENT; + f->state = LS_REQSENT; break; } @@ -565,20 +584,20 @@ static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len) fsm_sdata(f, (u_char)code, id, inp, len); if (code == CONFACK) { - if (f->state == ACKRCVD) { + if (f->state == LS_ACKRCVD) { UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ - f->state = OPENED; + f->state = LS_OPENED; if (f->callbacks->up) (*f->callbacks->up)(f); /* Inform upper layers */ } else - f->state = ACKSENT; + f->state = LS_ACKSENT; f->nakloops = 0; } else { /* we sent CONFACK or CONFREJ */ - if (f->state != ACKRCVD) - f->state = REQSENT; + if (f->state != LS_ACKRCVD) + f->state = LS_REQSENT; if( code == CONFNAK ) ++f->nakloops; } @@ -590,8 +609,8 @@ static void fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len) */ static void fsm_rconfack(fsm *f, int id, u_char *inp, int len) { - FSMDEBUG((LOG_INFO, "fsm_rconfack(%s): Rcvd id %d state=%d\n", - PROTO_NAME(f), id, f->state)); + FSMDEBUG((LOG_INFO, "fsm_rconfack(%s): Rcvd id %d state=%d (%s)\n", + PROTO_NAME(f), id, f->state, ppperr_strerr[f->state])); if (id != f->reqid || f->seen_ack) /* Expected id? */ return; /* Nope, toss... */ @@ -605,37 +624,37 @@ static void fsm_rconfack(fsm *f, int id, u_char *inp, int len) f->seen_ack = 1; switch (f->state) { - case CLOSED: - case STOPPED: + case LS_CLOSED: + case LS_STOPPED: fsm_sdata(f, TERMACK, (u_char)id, NULL, 0); break; - case REQSENT: - f->state = ACKRCVD; + case LS_REQSENT: + f->state = LS_ACKRCVD; f->retransmits = f->maxconfreqtransmits; break; - case ACKRCVD: + case LS_ACKRCVD: /* Huh? an extra valid Ack? oh well... */ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ fsm_sconfreq(f, 0); - f->state = REQSENT; + f->state = LS_REQSENT; break; - case ACKSENT: + case LS_ACKSENT: UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ - f->state = OPENED; + f->state = LS_OPENED; f->retransmits = f->maxconfreqtransmits; if (f->callbacks->up) (*f->callbacks->up)(f); /* Inform upper layers */ break; - case OPENED: + case LS_OPENED: /* Go down and restart negotiation */ if (f->callbacks->down) (*f->callbacks->down)(f); /* Inform upper layers */ fsm_sconfreq(f, 0); /* Send initial Configure-Request */ - f->state = REQSENT; + f->state = LS_REQSENT; break; } } @@ -649,8 +668,8 @@ static void fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len) int (*proc) (fsm *, u_char *, int); int ret; - FSMDEBUG((LOG_INFO, "fsm_rconfnakrej(%s): Rcvd id %d state=%d\n", - PROTO_NAME(f), id, f->state)); + FSMDEBUG((LOG_INFO, "fsm_rconfnakrej(%s): Rcvd id %d state=%d (%s)\n", + PROTO_NAME(f), id, f->state, ppperr_strerr[f->state])); if (id != f->reqid || f->seen_ack) /* Expected id? */ return; /* Nope, toss... */ @@ -664,34 +683,34 @@ static void fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len) f->seen_ack = 1; switch (f->state) { - case CLOSED: - case STOPPED: + case LS_CLOSED: + case LS_STOPPED: fsm_sdata(f, TERMACK, (u_char)id, NULL, 0); break; - case REQSENT: - case ACKSENT: + case LS_REQSENT: + case LS_ACKSENT: /* They didn't agree to what we wanted - try another request */ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ if (ret < 0) - f->state = STOPPED; /* kludge for stopping CCP */ + f->state = LS_STOPPED; /* kludge for stopping CCP */ else fsm_sconfreq(f, 0); /* Send Configure-Request */ break; - case ACKRCVD: + case LS_ACKRCVD: /* Got a Nak/reject when we had already had an Ack?? oh well... */ UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ fsm_sconfreq(f, 0); - f->state = REQSENT; + f->state = LS_REQSENT; break; - case OPENED: + case LS_OPENED: /* Go down and restart negotiation */ if (f->callbacks->down) (*f->callbacks->down)(f); /* Inform upper layers */ fsm_sconfreq(f, 0); /* Send initial Configure-Request */ - f->state = REQSENT; + f->state = LS_REQSENT; break; } } @@ -702,16 +721,16 @@ static void fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len) */ static void fsm_rtermreq(fsm *f, int id, u_char *p, int len) { - FSMDEBUG((LOG_INFO, "fsm_rtermreq(%s): Rcvd id %d state=%d\n", - PROTO_NAME(f), id, f->state)); + FSMDEBUG((LOG_INFO, "fsm_rtermreq(%s): Rcvd id %d state=%d (%s)\n", + PROTO_NAME(f), id, f->state, ppperr_strerr[f->state])); switch (f->state) { - case ACKRCVD: - case ACKSENT: - f->state = REQSENT; /* Start over but keep trying */ + case LS_ACKRCVD: + case LS_ACKSENT: + f->state = LS_REQSENT; /* Start over but keep trying */ break; - case OPENED: + case LS_OPENED: if (len > 0) { FSMDEBUG((LOG_INFO, "%s terminated by peer (%x)\n", PROTO_NAME(f), p)); } else { @@ -720,7 +739,7 @@ static void fsm_rtermreq(fsm *f, int id, u_char *p, int len) if (f->callbacks->down) (*f->callbacks->down)(f); /* Inform upper layers */ f->retransmits = 0; - f->state = STOPPING; + f->state = LS_STOPPING; TIMEOUT(fsm_timeout, f, f->timeouttime); break; } @@ -734,28 +753,28 @@ static void fsm_rtermreq(fsm *f, int id, u_char *p, int len) */ static void fsm_rtermack(fsm *f) { - FSMDEBUG((LOG_INFO, "fsm_rtermack(%s): state=%d\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "fsm_rtermack(%s): state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); switch (f->state) { - case CLOSING: + case LS_CLOSING: UNTIMEOUT(fsm_timeout, f); - f->state = CLOSED; + f->state = LS_CLOSED; if( f->callbacks->finished ) (*f->callbacks->finished)(f); break; - case STOPPING: + case LS_STOPPING: UNTIMEOUT(fsm_timeout, f); - f->state = STOPPED; + f->state = LS_STOPPED; if( f->callbacks->finished ) (*f->callbacks->finished)(f); break; - case ACKRCVD: - f->state = REQSENT; + case LS_ACKRCVD: + f->state = LS_REQSENT; break; - case OPENED: + case LS_OPENED: if (f->callbacks->down) (*f->callbacks->down)(f); /* Inform upper layers */ fsm_sconfreq(f, 0); @@ -771,8 +790,8 @@ static void fsm_rcoderej(fsm *f, u_char *inp, int len) { u_char code, id; - FSMDEBUG((LOG_INFO, "fsm_rcoderej(%s): state=%d\n", - PROTO_NAME(f), f->state)); + FSMDEBUG((LOG_INFO, "fsm_rcoderej(%s): state=%d (%s)\n", + PROTO_NAME(f), f->state, ppperr_strerr[f->state])); if (len < HEADERLEN) { FSMDEBUG((LOG_INFO, "fsm_rcoderej: Rcvd short Code-Reject packet!\n")); @@ -783,8 +802,8 @@ static void fsm_rcoderej(fsm *f, u_char *inp, int len) FSMDEBUG((LOG_WARNING, "%s: Rcvd Code-Reject for code %d, id %d\n", PROTO_NAME(f), code, id)); - if( f->state == ACKRCVD ) - f->state = REQSENT; + if( f->state == LS_ACKRCVD ) + f->state = LS_REQSENT; } @@ -796,7 +815,7 @@ static void fsm_sconfreq(fsm *f, int retransmit) u_char *outp; int cilen; - if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){ + if( f->state != LS_REQSENT && f->state != LS_ACKRCVD && f->state != LS_ACKSENT ){ /* Not currently negotiating - reset options */ if( f->callbacks->resetci ) (*f->callbacks->resetci)(f); diff --git a/src/netif/ppp/fsm.h b/src/netif/ppp/fsm.h index 0e1d9f61..e5fa575f 100644 --- a/src/netif/ppp/fsm.h +++ b/src/netif/ppp/fsm.h @@ -48,13 +48,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: fsm.h,v 1.1 2003/05/27 14:37:56 jani Exp $ + * $Id: fsm.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $ */ #ifndef FSM_H #define FSM_H - /***************************************************************************** ************************* PUBLIC DEFINITIONS ********************************* *****************************************************************************/ @@ -78,16 +77,16 @@ /* * Link states. */ -#define INITIAL 0 /* Down, hasn't been opened */ -#define STARTING 1 /* Down, been opened */ -#define CLOSED 2 /* Up, hasn't been opened */ -#define STOPPED 3 /* Open, waiting for down event */ -#define CLOSING 4 /* Terminating the connection, not open */ -#define STOPPING 5 /* Terminating, but open */ -#define REQSENT 6 /* We've sent a Config Request */ -#define ACKRCVD 7 /* We've received a Config Ack */ -#define ACKSENT 8 /* We've sent a Config Ack */ -#define OPENED 9 /* Connection available */ +#define LS_INITIAL 0 /* Down, hasn't been opened */ +#define LS_STARTING 1 /* Down, been opened */ +#define LS_CLOSED 2 /* Up, hasn't been opened */ +#define LS_STOPPED 3 /* Open, waiting for down event */ +#define LS_CLOSING 4 /* Terminating the connection, not open */ +#define LS_STOPPING 5 /* Terminating, but open */ +#define LS_REQSENT 6 /* We've sent a Config Request */ +#define LS_ACKRCVD 7 /* We've received a Config Ack */ +#define LS_ACKSENT 8 /* We've sent a Config Ack */ +#define LS_OPENED 9 /* Connection available */ /* @@ -139,9 +138,9 @@ typedef struct fsm_callbacks { (fsm*, u_char*, int); int (*reqci) /* Request peer's Configuration Information */ (fsm*, u_char*, int*, int); - void (*up) /* Called when fsm reaches OPENED state */ + void (*up) /* Called when fsm reaches LS_OPENED state */ (fsm*); - void (*down) /* Called when fsm leaves OPENED state */ + void (*down) /* Called when fsm leaves LS_OPENED state */ (fsm*); void (*starting) /* Called when we want the lower layer */ (fsm*); @@ -182,6 +181,4 @@ void fsm_input (fsm*, u_char*, int); void fsm_protreject (fsm*); void fsm_sdata (fsm*, u_char, u_char, u_char*, int); - #endif /* FSM_H */ - diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 9b8ce9ab..162ffab9 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -49,16 +49,19 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#include +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ #include "ppp.h" -#if PPP_SUPPORT > 0 +#include "pppdebug.h" + #include "auth.h" #include "fsm.h" #include "vj.h" #include "ipcp.h" -#include "pppdebug.h" +#include /*************************/ /*** LOCAL DEFINITIONS ***/ @@ -164,8 +167,8 @@ static fsm_callbacks ipcp_callbacks = { /* IPCP callback routines */ ipcp_nakci, /* NAK our Configuration Information */ ipcp_rejci, /* Reject our Configuration Information */ ipcp_reqci, /* Request peer's Configuration Information */ - ipcp_up, /* Called when fsm reaches OPENED state */ - ipcp_down, /* Called when fsm leaves OPENED state */ + ipcp_up, /* Called when fsm reaches LS_OPENED state */ + ipcp_down, /* Called when fsm leaves LS_OPENED state */ NULL, /* Called when we want the lower layer up */ ipcp_finished, /* Called when we want the lower layer down */ NULL, /* Called when Protocol-Reject received */ @@ -213,11 +216,11 @@ static void ipcp_init(int unit) wo->neg_addr = 1; wo->ouraddr = 0; -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT wo->neg_vj = 1; -#else +#else /* VJ_SUPPORT */ wo->neg_vj = 0; -#endif +#endif /* VJ_SUPPORT */ wo->vj_protocol = IPCP_VJ_COMP; wo->maxslotindex = MAX_SLOTS - 1; wo->cflag = 0; @@ -225,11 +228,11 @@ static void ipcp_init(int unit) wo->default_route = 1; ao->neg_addr = 1; -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT ao->neg_vj = 1; -#else +#else /* VJ_SUPPORT */ ao->neg_vj = 0; -#endif +#endif /* VJ_SUPPORT */ ao->maxslotindex = MAX_SLOTS - 1; ao->cflag = 1; @@ -533,7 +536,7 @@ bad: /* * ipcp_nakci - Peer has sent a NAK for some of our CIs. * This should not modify any state if the Nak is bad - * or if IPCP is in the OPENED state. + * or if IPCP is in the LS_OPENED state. * * Returns: * 0 - Nak was bad. @@ -716,7 +719,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len) /* * OK, the Nak is good. Now we can update state. */ - if (f->state != OPENED) + if (f->state != LS_OPENED) *go = try; return 1; @@ -823,7 +826,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) /* * Now we can update state. */ - if (f->state != OPENED) + if (f->state != LS_OPENED) *go = try; return 1; diff --git a/src/netif/ppp/ipcp.h b/src/netif/ppp/ipcp.h index 416aa79a..7368fb97 100644 --- a/src/netif/ppp/ipcp.h +++ b/src/netif/ppp/ipcp.h @@ -48,7 +48,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ipcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $ + * $Id: ipcp.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $ */ #ifndef IPCP_H @@ -121,6 +121,4 @@ extern struct protent ipcp_protent; *** PUBLIC FUNCTIONS *** ***********************/ - #endif /* IPCP_H */ - diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index 20745d07..57b0a3d9 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -50,16 +50,21 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#include - + +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#if PPP_SUPPORT > 0 +#include "pppdebug.h" + #include "fsm.h" #include "chap.h" #include "magic.h" #include "auth.h" #include "lcp.h" -#include "pppdebug.h" + +#include #if PPPOE_SUPPORT #include "ppp_oe.h" @@ -159,8 +164,8 @@ static fsm_callbacks lcp_callbacks = { /* LCP callback routines */ lcp_nakci, /* NAK our Configuration Information */ lcp_rejci, /* Reject our Configuration Information */ lcp_reqci, /* Request peer's Configuration Information */ - lcp_up, /* Called when fsm reaches OPENED state */ - lcp_down, /* Called when fsm leaves OPENED state */ + lcp_up, /* Called when fsm reaches LS_OPENED state */ + lcp_down, /* Called when fsm leaves LS_OPENED state */ lcp_starting, /* Called when we want the lower layer up */ lcp_finished, /* Called when we want the lower layer down */ NULL, /* Called when Protocol-Reject received */ @@ -291,14 +296,14 @@ void lcp_close(int unit, char *reason) if (lcp_phase[unit] != PHASE_DEAD) lcp_phase[unit] = PHASE_TERMINATE; - if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) { + if (f->state == LS_STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) { /* * This action is not strictly according to the FSM in RFC1548, * but it does mean that the program terminates if you do an * lcp_close() in passive/silent mode when a connection hasn't * been established. */ - f->state = CLOSED; + f->state = LS_CLOSED; lcp_finished(f); } else @@ -353,7 +358,7 @@ void lcp_sprotrej(int unit, u_char *p, int len) { /* * Send back the protocol and the information field of the - * rejected packet. We only get here if LCP is in the OPENED state. + * rejected packet. We only get here if LCP is in the LS_OPENED state. */ fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, @@ -389,7 +394,7 @@ static int lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len) break; case ECHOREQ: - if (f->state != OPENED) + if (f->state != LS_OPENED) break; LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d\n", id)); magp = inp; @@ -436,9 +441,9 @@ static void lcp_rprotrej(fsm *f, u_char *inp, int len) /* * Protocol-Reject packets received in any state other than the LCP - * OPENED state SHOULD be silently discarded. + * LS_OPENED state SHOULD be silently discarded. */ - if( f->state != OPENED ){ + if( f->state != LS_OPENED ){ LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d\n", f->state)); return; @@ -714,7 +719,7 @@ bad: /* * lcp_nakci - Peer has sent a NAK for some of our CIs. * This should not modify any state if the Nak is bad - * or if LCP is in the OPENED state. + * or if LCP is in the LS_OPENED state. * * Returns: * 0 - Nak was bad. @@ -995,7 +1000,7 @@ static int lcp_nakci(fsm *f, u_char *p, int len) /* * OK, the Nak is good. Now we can update state. */ - if (f->state != OPENED) { + if (f->state != LS_OPENED) { if (looped_back) { if (++try.numloops >= lcp_loopbackfail) { LCPDEBUG((LOG_NOTICE, "Serial line is looped back.\n")); @@ -1018,7 +1023,7 @@ bad: /* * lcp_rejci - Peer has Rejected some of our CIs. * This should not modify any state if the Reject is bad - * or if LCP is in the OPENED state. + * or if LCP is in the LS_OPENED state. * * Returns: * 0 - Reject was bad. @@ -1143,7 +1148,7 @@ static int lcp_rejci(fsm *f, u_char *p, int len) /* * Now we can update state. */ - if (f->state != OPENED) + if (f->state != LS_OPENED) *go = try; return 1; @@ -1871,7 +1876,7 @@ static int lcp_printpkt( static void LcpLinkFailure (fsm *f) { - if (f->state == OPENED) { + if (f->state == LS_OPENED) { LCPDEBUG((LOG_INFO, "No response to %d echo-requests\n", lcp_echos_pending)); LCPDEBUG((LOG_NOTICE, "Serial link appears to be disconnected.\n")); lcp_close(f->unit, "Peer not responding"); @@ -1954,7 +1959,7 @@ static void LcpSendEchoRequest (fsm *f) /* * Make and send the echo request frame. */ - if (f->state == OPENED) { + if (f->state == LS_OPENED) { lcp_magic = lcp_gotoptions[f->unit].magicnumber; pktp = pkt; PUTLONG(lcp_magic, pktp); diff --git a/src/netif/ppp/lcp.h b/src/netif/ppp/lcp.h index 3876d39a..ba44ccb9 100644 --- a/src/netif/ppp/lcp.h +++ b/src/netif/ppp/lcp.h @@ -48,13 +48,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $ + * $Id: lcp.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $ */ #ifndef LCP_H #define LCP_H - /************************* *** PUBLIC DEFINITIONS *** *************************/ @@ -166,4 +165,3 @@ extern struct protent lcp_protent; #define DEFLOOPBACKFAIL 10 #endif /* LCP_H */ - diff --git a/src/netif/ppp/md5.c b/src/netif/ppp/md5.c index ef775936..c582faf9 100644 --- a/src/netif/ppp/md5.c +++ b/src/netif/ppp/md5.c @@ -31,11 +31,16 @@ *********************************************************************** */ +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#if CHAP_SUPPORT || MD5_SUPPORT + #include "ppp.h" -#include "md5.h" #include "pppdebug.h" -#if CHAP_SUPPORT > 0 || MD5_SUPPORT > 0 +#include "md5.h" /* *********************************************************************** @@ -302,5 +307,6 @@ static void Transform (u32_t *buf, u32_t *in) buf[3] += d; } -#endif +#endif /* CHAP_SUPPORT || MD5_SUPPORT */ +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/pap.c b/src/netif/ppp/pap.c index 41faf537..f63fa677 100644 --- a/src/netif/ppp/pap.c +++ b/src/netif/ppp/pap.c @@ -49,13 +49,17 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#if PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#include "auth.h" -#include "pap.h" #include "pppdebug.h" - -#if PAP_SUPPORT > 0 +#include "auth.h" +#include "pap.h" /***********************************/ /*** LOCAL FUNCTION DECLARATIONS ***/ @@ -602,7 +606,8 @@ static int upap_printpkt( LWIP_UNUSED_ARG(arg); return 0; } -#endif +#endif /* 0 */ #endif /* PAP_SUPPORT */ +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/pap.h b/src/netif/ppp/pap.h index d8d43284..6193f6c8 100644 --- a/src/netif/ppp/pap.h +++ b/src/netif/ppp/pap.h @@ -49,11 +49,10 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ - #ifndef PAP_H #define PAP_H -#if PAP_SUPPORT > 0 +#if PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ /************************* *** PUBLIC DEFINITIONS *** diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index b5aac3c9..7ec0a2df 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -78,31 +78,34 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ - -#include - + +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" -#if PPP_SUPPORT > 0 +#include "pppdebug.h" + #include "randm.h" #include "fsm.h" -#if PAP_SUPPORT > 0 +#if PAP_SUPPORT #include "pap.h" -#endif -#if CHAP_SUPPORT > 0 +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT #include "chap.h" -#endif +#endif /* CHAP_SUPPORT */ #include "ipcp.h" #include "lcp.h" #include "magic.h" #include "auth.h" -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT #include "vj.h" -#endif -#if PPPOE_SUPPORT > 0 +#endif /* VJ_SUPPORT */ +#if PPPOE_SUPPORT #include "ppp_oe.h" -#endif +#endif /* PPPOE_SUPPORT */ -#include "pppdebug.h" +#include /*************************/ /*** LOCAL DEFINITIONS ***/ @@ -140,7 +143,7 @@ typedef struct PPPControl_s { #if PPPOE_SUPPORT struct netif *ethif; struct pppoe_softc *pppoe_sc; -#endif +#endif /* PPPOE_SUPPORT */ int if_up; /* True when the interface is up. */ int errCode; /* Code indicating why interface is down. */ #if PPPOS_SUPPORT @@ -152,17 +155,17 @@ typedef struct PPPControl_s { char inEscaped; /* Escape next character. */ u16_t inProtocol; /* The input protocol code. */ u16_t inFCS; /* Input Frame Check Sequence value. */ -#endif +#endif /* PPPOS_SUPPORT */ int mtu; /* Peer's mru */ int pcomp; /* Does peer accept protocol compression? */ int accomp; /* Does peer accept addr/ctl compression? */ u_long lastXMit; /* Time of last transmission. */ ext_accm inACCM; /* Async-Ctl-Char-Map for input. */ ext_accm outACCM; /* Async-Ctl-Char-Map for output. */ -#if PPPOS_SUPPORT && VJ_SUPPORT > 0 +#if PPPOS_SUPPORT && VJ_SUPPORT int vjEnabled; /* Flag indicating VJ compression enabled. */ struct vjcompress vjComp; /* Van Jabobsen compression header. */ -#endif +#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ struct netif netif; @@ -192,7 +195,7 @@ struct npioctl { static void pppMain(void *pd); static void pppDrop(PPPControl *pc); static void pppInProc(int pd, u_char *s, int l); -#endif +#endif /* PPPOS_SUPPORT */ /******************************/ @@ -209,19 +212,19 @@ static PPPControl pppControl[NUM_PPP]; /* The PPP interface control blocks. */ */ struct protent *ppp_protocols[] = { &lcp_protent, -#if PAP_SUPPORT > 0 +#if PAP_SUPPORT &pap_protent, -#endif -#if CHAP_SUPPORT > 0 +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT &chap_protent, -#endif -#if CBCP_SUPPORT > 0 +#endif /* CHAP_SUPPORT */ +#if CBCP_SUPPORT &cbcp_protent, -#endif +#endif /* CBCP_SUPPORT */ &ipcp_protent, -#if CCP_SUPPORT > 0 +#if CCP_SUPPORT &ccp_protent, -#endif +#endif /* CCP_SUPPORT */ NULL }; @@ -410,9 +413,9 @@ pppInit(void) memset(&lwip_stats.link, 0, sizeof(lwip_stats.link)); #endif -#if PPPOE_SUPPORT > 0 +#if PPPOE_SUPPORT pppoe_init(); -#endif +#endif /* PPPOE_SUPPORT */ return ERR_OK; } @@ -504,7 +507,9 @@ int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, lcp_init(pd); pc = &pppControl[pd]; pc->fd = fd; +#if PPPOE_SUPPORT pc->ethif= NULL; +#endif /* PPPOE_SUPPORT */ pc->kill_link = 0; pc->sig_hup = 0; pc->if_up = 0; @@ -515,10 +520,10 @@ int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, pc->inEscaped = 0; pc->lastXMit = 0; -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT pc->vjEnabled = 0; vj_compress_init(&pc->vjComp); -#endif +#endif /* VJ_SUPPORT */ /* * Default the in and out accm so that escape and flag characters @@ -603,9 +608,9 @@ int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const cha pc->inHead = NULL; pc->inTail = NULL; pc->inEscaped = 0; -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT pc->vjEnabled = 0; -#endif +#endif /* VJ_SUPPORT */ #endif /* PPPOS_SUPPORT */ pc->ethif= ethif; @@ -855,7 +860,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i return ERR_MEM; } -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT /* * Attempt Van Jacobson header compression if VJ is configured and * this is an IP packet. @@ -883,7 +888,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i return ERR_VAL; } } -#endif +#endif /* VJ_SUPPORT */ tailMB = headMB; @@ -1294,7 +1299,7 @@ int sifvjcomp( int maxcid ) { -#if PPPOS_SUPPORT > 0 && VJ_SUPPORT > 0 +#if PPPOS_SUPPORT && VJ_SUPPORT PPPControl *pc = &pppControl[pd]; pc->vjEnabled = vjcomp; @@ -1302,7 +1307,7 @@ int sifvjcomp( pc->vjComp.maxSlotIndex = maxcid; PPPDEBUG((LOG_INFO, "sifvjcomp: VJ compress enable=%d slot=%d max slot=%d\n", vjcomp, cidcomp, maxcid)); -#endif +#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ return 0; } @@ -1336,8 +1341,10 @@ int sifup(int pd) if (netif_add(&pc->netif, &pc->addrs.our_ipaddr, &pc->addrs.netmask, &pc->addrs.his_ipaddr, (void *)pd, pppifNetifInit, ip_input)) { netif_set_up(&pc->netif); +#if LWIP_DHCP /* ugly workaround for storing a reference to the ppp related info*/ pc->netif.dhcp = (struct dhcp *) &pc->addrs; +#endif /* LWIP_DHCP */ pc->if_up = 1; pc->errCode = PPPERR_NONE; @@ -1492,56 +1499,57 @@ int cifdefaultroute(int pd, u32_t l, u32_t g) * to section 4 of RFC 1661: The Point-To-Point Protocol. */ static void pppMain(void *arg) { - int pd = (int)arg; - struct pbuf *p; - PPPControl* pc; + int pd = (int)arg; + struct pbuf *p; + PPPControl* pc; + int c; - pc = &pppControl[pd]; + pc = &pppControl[pd]; - p = pbuf_alloc(PBUF_RAW, PPP_MRU+PPP_HDRLEN, PBUF_RAM); - if(!p) { - LWIP_ASSERT("p != NULL", p); - pc->errCode = PPPERR_ALLOC; - goto out; + p = pbuf_alloc(PBUF_RAW, PPP_MRU+PPP_HDRLEN, PBUF_RAM); + if (!p) { + LWIP_ASSERT("p != NULL", p); + pc->errCode = PPPERR_ALLOC; + goto out; + } + + /* + * Start the connection and handle incoming events (packet or timeout). + */ + PPPDEBUG((LOG_INFO, "pppMain: unit %d: Connecting\n", pd)); + tcpip_callback(pppStartCB, arg); + while (lcp_phase[pd] != PHASE_DEAD) { + if (pc->kill_link) { + PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d kill_link -> pppStopCB\n", pd)); + pc->errCode = PPPERR_USER; + /* This will leave us at PHASE_DEAD. */ + tcpip_callback(pppStopCB, arg); + pc->kill_link = 0; + } else if (pc->sig_hup) { + PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d sig_hup -> pppHupCB\n", pd)); + pc->sig_hup = 0; + tcpip_callback(pppHupCB, arg); + } else { + c = sio_read(pc->fd, p->payload, p->len); + if(c > 0) { + pppInProc(pd, p->payload, c); + } else { + PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d sio_read len=%d returned %d\n", pd, p->len, c)); + sys_msleep(1); /* give other tasks a chance to run */ + } } - - /* - * Start the connection and handle incoming events (packet or timeout). - */ - PPPDEBUG((LOG_INFO, "pppMain: unit %d: Connecting\n", pd)); - tcpip_callback(pppStartCB, arg); - while (lcp_phase[pd] != PHASE_DEAD) { - if (pc->kill_link) { - PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d kill_link -> pppStopCB\n", pd)); - pc->errCode = PPPERR_USER; - /* This will leave us at PHASE_DEAD. */ - tcpip_callback(pppStopCB, arg); - pc->kill_link = 0; - } - else if (pc->sig_hup) { - PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d sig_hup -> pppHupCB\n", pd)); - pc->sig_hup = 0; - tcpip_callback(pppHupCB, arg); - } else { - int c = sio_read(pc->fd, p->payload, p->len); - if(c > 0) { - pppInProc(pd, p->payload, c); - } else { - PPPDEBUG((LOG_DEBUG, "pppMainWakeup: unit %d sio_read len=%d returned %d\n", pd, p->len, c)); - sys_msleep(1); /* give other tasks a chance to run */ - } - } - } - PPPDEBUG((LOG_INFO, "pppMain: unit %d: PHASE_DEAD\n", pd)); - pppDrop(pc); /* bug fix #17726 */ - pbuf_free(p); + } + PPPDEBUG((LOG_INFO, "pppMain: unit %d: PHASE_DEAD\n", pd)); + pppDrop(pc); /* bug fix #17726 */ + pbuf_free(p); out: - PPPDEBUG((LOG_DEBUG, "pppMain: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); - if(pc->linkStatusCB) - pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL); + PPPDEBUG((LOG_DEBUG, "pppMain: unit %d: linkStatusCB=%lx errCode=%d\n", pd, pc->linkStatusCB, pc->errCode)); + if(pc->linkStatusCB) { + pc->linkStatusCB(pc->linkStatusCtx, pc->errCode ? pc->errCode : PPPERR_PROTOCOL, NULL); + } - pc->openFlag = 0; + pc->openFlag = 0; } #endif /* PPPOS_SUPPORT */ @@ -1647,7 +1655,7 @@ static void pppInput(void *arg) switch(protocol) { case PPP_VJC_COMP: /* VJ compressed TCP */ -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT PPPDEBUG((LOG_INFO, "pppInput[%d]: vj_comp in pbuf len=%d\n", pd, nb->len)); /* * Clip off the VJ header and prepend the rebuilt TCP/IP header and @@ -1659,13 +1667,13 @@ static void pppInput(void *arg) } /* Something's wrong so drop it. */ PPPDEBUG((LOG_WARNING, "pppInput[%d]: Dropping VJ compressed\n", pd)); -#else +#else /* VJ_SUPPORT */ /* No handler for this protocol so drop the packet. */ PPPDEBUG((LOG_INFO, "pppInput[%d]: drop VJ Comp in %d:%s\n", pd, nb->len, nb->payload)); -#endif /* VJ_SUPPORT > 0 */ +#endif /* VJ_SUPPORT */ break; case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT PPPDEBUG((LOG_INFO, "pppInput[%d]: vj_un in pbuf len=%d\n", pd, nb->len)); /* * Process the TCP/IP header for VJ header compression and then pass @@ -1677,12 +1685,12 @@ static void pppInput(void *arg) } /* Something's wrong so drop it. */ PPPDEBUG((LOG_WARNING, "pppInput[%d]: Dropping VJ uncompressed\n", pd)); -#else +#else /* VJ_SUPPORT */ /* No handler for this protocol so drop the packet. */ PPPDEBUG((LOG_INFO, "pppInput[%d]: drop VJ UnComp in %d:.*H\n", pd, nb->len, LWIP_MIN(nb->len * 2, 40), nb->payload)); -#endif /* VJ_SUPPORT > 0 */ +#endif /* VJ_SUPPORT */ break; case PPP_IP: /* Internet Protocol */ PPPDEBUG((LOG_INFO, "pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len)); @@ -1751,9 +1759,9 @@ static void pppDrop(PPPControl *pc) pc->inHead = NULL; pc->inTail = NULL; } -#if VJ_SUPPORT > 0 +#if VJ_SUPPORT vj_uncompress_err(&pc->vjComp); -#endif +#endif /* VJ_SUPPORT */ #if LINK_STATS lwip_stats.link.drop++; diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index d4c550db..eaf2f401 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -36,7 +36,9 @@ #include "lwip/opt.h" -#if PPP_SUPPORT > 0 +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/def.h" #include "lwip/sio.h" #include "lwip/api.h" #include "lwip/sockets.h" @@ -210,9 +212,9 @@ enum NPmode { #define BZERO(s, n) memset(s, 0, n) #if PPP_DEBUG #define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); } -#else +#else /* PPP_DEBUG */ #define PRINTMSG(m, l) -#endif +#endif /* PPP_DEBUG */ /* * MAKEHEADER - Add PPP Header fields to a packet. @@ -380,6 +382,8 @@ void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd) */ int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx); +/* for source code compatibility */ +#define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls) /* * Open a new PPP Over Ethernet (PPPOE) connection. */ diff --git a/src/netif/ppp/ppp_oe.c b/src/netif/ppp/ppp_oe.c index aa4fac62..e62969ff 100644 --- a/src/netif/ppp/ppp_oe.c +++ b/src/netif/ppp/ppp_oe.c @@ -68,18 +68,21 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include -#include - +#include "lwip/opt.h" + +#if PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "ppp.h" +#include "ppp_oe.h" #include "pppdebug.h" #include "netif/etharp.h" -#include "queue.h" -#include "ppp_oe.h" #include "lwip/sys.h" -#if PPPOE_SUPPORT > 0 +#include "queue.h" + +#include +#include /* Add a 16 bit unsigned value to a buffer pointed to by PTR */ #define PPPOE_ADD_16(PTR, VAL) \ @@ -1089,4 +1092,5 @@ pppoe_clear_softc(struct pppoe_softc *sc, const char *message) sc->sc_session = 0; } -#endif /* PPPOE_SUPPORT > 0 */ +#endif /* PPPOE_SUPPORT */ + diff --git a/src/netif/ppp/pppdebug.h b/src/netif/ppp/pppdebug.h index de1478ce..bd4dc063 100644 --- a/src/netif/ppp/pppdebug.h +++ b/src/netif/ppp/pppdebug.h @@ -59,7 +59,7 @@ typedef enum { */ void ppp_trace(int level, const char *format,...); -#if PPP_DEBUG > 0 +#if PPP_DEBUG #define AUTHDEBUG(a) ppp_trace a #define IPCPDEBUG(a) ppp_trace a @@ -71,7 +71,7 @@ void ppp_trace(int level, const char *format,...); #define TRACELCP 1 -#else +#else /* PPP_DEBUG */ #define AUTHDEBUG(a) #define IPCPDEBUG(a) @@ -84,6 +84,6 @@ void ppp_trace(int level, const char *format,...); #define TRACELCP 0 -#endif +#endif /* PPP_DEBUG */ #endif /* PPPDEBUG_H */ diff --git a/src/netif/ppp/randm.c b/src/netif/ppp/randm.c index ee3a837d..1916c4ad 100644 --- a/src/netif/ppp/randm.c +++ b/src/netif/ppp/randm.c @@ -31,15 +31,18 @@ * Extracted from avos. *****************************************************************************/ -#include "ppp.h" -#if PPP_SUPPORT > 0 +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + #include "md5.h" #include "randm.h" +#include "ppp.h" #include "pppdebug.h" -#if MD5_SUPPORT>0 /* this module depends on MD5 */ +#if MD5_SUPPORT /* this module depends on MD5 */ #define RANDPOOLSZ 16 /* Bytes stored in the pool of randomness. */ /*****************************/ @@ -235,8 +238,6 @@ u32_t avRandom() return ((((u32_t)rand() << 16) + rand()) + avRandomSeed); } - - #endif /* MD5_SUPPORT */ -#endif /* PPP_SUPPORT */ +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/randm.h b/src/netif/ppp/randm.h index baa42f0c..dc4cc557 100644 --- a/src/netif/ppp/randm.h +++ b/src/netif/ppp/randm.h @@ -58,9 +58,9 @@ void avChurnRand(char *randData, u32_t randLen); */ #if MD5_SUPPORT #define avRandomize() avChurnRand(NULL, 0) -#else +#else /* MD5_SUPPORT */ void avRandomize(void); -#endif +#endif /* MD5_SUPPORT */ /* * Use the random pool to generate random data. This degrades to pseudo diff --git a/src/netif/ppp/vj.c b/src/netif/ppp/vj.c index c7adbe98..81e2194a 100644 --- a/src/netif/ppp/vj.c +++ b/src/netif/ppp/vj.c @@ -28,13 +28,18 @@ * for a 16 bit processor. */ -#include +#include "lwip/opt.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ #include "ppp.h" -#include "vj.h" #include "pppdebug.h" -#if VJ_SUPPORT > 0 +#include "vj.h" + +#include + +#if VJ_SUPPORT #if LINK_STATS #define INCR(counter) ++comp->stats.counter @@ -579,7 +584,7 @@ int vj_uncompress_tcp( cs->cs_ip.ip_sum = (u_short)(~tmp); /* Remove the compressed header and prepend the uncompressed header. */ - if(pbuf_header(n0, -vjlen)) { + if(pbuf_header(n0, -((s16_t)(vjlen)))) { /* Can we cope with this failing? Just assert for now */ LWIP_ASSERT("pbuf_header failed\n", 0); goto bad; @@ -641,6 +646,6 @@ bad: return (-1); } -#endif - +#endif /* VJ_SUPPORT */ +#endif /* PPP_SUPPORT */ diff --git a/src/netif/ppp/vjbsdhdr.h b/src/netif/ppp/vjbsdhdr.h index a089352a..de05b5d7 100644 --- a/src/netif/ppp/vjbsdhdr.h +++ b/src/netif/ppp/vjbsdhdr.h @@ -3,7 +3,6 @@ #include "lwip/tcp.h" - /* * Structure of an internet header, naked of options. *