re-added PPPoS code from the previous port, it builds, maybe it works

This commit is contained in:
Sylvain Rochet 2012-06-03 20:05:40 +02:00
parent 10175caa38
commit 0663421d01
5 changed files with 1130 additions and 83 deletions

View File

@ -661,7 +661,7 @@ link_terminated(unit)
lcp_lowerdown(0); lcp_lowerdown(0);
new_phase(PHASE_DEAD); new_phase(PHASE_DEAD);
pppLinkTerminated(unit);
#if 0 #if 0
/* /*
* Delete pid files before disestablishing ppp. Otherwise it * Delete pid files before disestablishing ppp. Otherwise it
@ -728,6 +728,8 @@ link_down(unit)
} }
/* XXX if doing_multilink, should do something to stop /* XXX if doing_multilink, should do something to stop
network-layer traffic on the link */ network-layer traffic on the link */
pppLinkDown(unit);
} }
void upper_layers_down(int unit) void upper_layers_down(int unit)
@ -1109,6 +1111,7 @@ void
auth_withpeer_fail(unit, protocol) auth_withpeer_fail(unit, protocol)
int unit, protocol; int unit, protocol;
{ {
int errcode = PPPERR_AUTHFAIL;
/* /*
* We've failed to authenticate ourselves to our peer. * We've failed to authenticate ourselves to our peer.
* Some servers keep sending CHAP challenges, but there * Some servers keep sending CHAP challenges, but there
@ -1116,6 +1119,13 @@ auth_withpeer_fail(unit, protocol)
* authentication secrets. * authentication secrets.
*/ */
status = EXIT_AUTH_TOPEER_FAILED; status = EXIT_AUTH_TOPEER_FAILED;
/*
* We've failed to authenticate ourselves to our peer.
* He'll probably take the link down, and there's not much
* we can do except wait for that.
*/
pppIOCtl(unit, PPPCTLS_ERRCODE, &errcode);
lcp_close(unit, "Failed to authenticate ourselves to peer"); lcp_close(unit, "Failed to authenticate ourselves to peer");
} }

View File

@ -207,6 +207,9 @@ lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */ lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */ lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */ lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
#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_echos_pending = 0; /* Number of outstanding echo msgs */
static int lcp_echo_number = 0; /* ID number of next echo frame */ static int lcp_echo_number = 0; /* ID number of next echo frame */
@ -403,6 +406,24 @@ lcp_init(unit)
ao->neg_pcompression = 1; ao->neg_pcompression = 1;
ao->neg_accompression = 1; ao->neg_accompression = 1;
ao->neg_endpoint = 1; ao->neg_endpoint = 1;
#if PPPOS_SUPPORT
/*
* Set transmit escape for the flag and escape characters plus anything
* set for the allowable options.
*/
memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
xmit_accm[unit][15] = 0x60;
xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF));
xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
LCPDEBUG(("lcp_init: xmit_accm=%X %X %X %X\n",
xmit_accm[unit][0],
xmit_accm[unit][1],
xmit_accm[unit][2],
xmit_accm[unit][3]));
#endif /* PPPOS_SUPPORT */
} }
@ -475,12 +496,27 @@ lcp_lowerup(unit)
* but accept A/C and protocol compressed packets * but accept A/C and protocol compressed packets
* if we are going to ask for A/C and protocol compression. * if we are going to ask for A/C and protocol compression.
*/ */
#if PPPOS_SUPPORT
ppp_set_xaccm(unit, &xmit_accm[unit]);
#endif /* PPPOS_SUPPORT */
if (ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0) < 0 if (ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0) < 0
|| ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff), || ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
wo->neg_pcompression, wo->neg_accompression) < 0) wo->neg_pcompression, wo->neg_accompression) < 0)
return; return;
peer_mru[unit] = PPP_MRU; peer_mru[unit] = PPP_MRU;
#if PPPOS_SUPPORT
lcp_allowoptions[unit].asyncmap = (u_long)xmit_accm[unit][0]
| ((u_long)xmit_accm[unit][1] << 8)
| ((u_long)xmit_accm[unit][2] << 16)
| ((u_long)xmit_accm[unit][3] << 24);
LCPDEBUG(("lcp_lowerup: asyncmap=%X %X %X %X\n",
xmit_accm[unit][3],
xmit_accm[unit][2],
xmit_accm[unit][1],
xmit_accm[unit][0]));
#endif /* PPPOS_SUPPORT */
if (listen_time != 0) { if (listen_time != 0) {
f->flags |= DELAYED_UP; f->flags |= DELAYED_UP;
TIMEOUTMS(lcp_delayed_up, f, listen_time); TIMEOUTMS(lcp_delayed_up, f, listen_time);

View File

@ -132,6 +132,9 @@ extern lcp_options lcp_wantoptions[];
extern lcp_options lcp_gotoptions[]; extern lcp_options lcp_gotoptions[];
extern lcp_options lcp_allowoptions[]; extern lcp_options lcp_allowoptions[];
extern lcp_options lcp_hisoptions[]; extern lcp_options lcp_hisoptions[];
#if PPPOS_SUPPORT
extern ext_accm xmit_accm[];
#endif /* #if PPPOS_SUPPORT */
#define DEFMRU 1500 /* Try for this */ #define DEFMRU 1500 /* Try for this */
#define MINMRU 128 /* No MRUs below this */ #define MINMRU 128 /* No MRUs below this */

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,35 @@
/* /*****************************************************************************
* ppp.h * ppp.h - Network Point to Point Protocol header file.
* *
* Created on: May 12, 2012 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* Author: gradator * portions Copyright (c) 1997 Global Election Systems Inc.
*/ *
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
* REVISION HISTORY
*
* 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP.
* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
* Original derived from BSD codes.
*****************************************************************************/
#include "lwip/opt.h" #include "lwip/opt.h"
#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
@ -38,6 +64,7 @@ typedef unsigned char bool;
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/timers.h" #include "lwip/timers.h"
#include "lwip/sio.h"
#include "pppdebug.h" #include "pppdebug.h"
@ -147,7 +174,7 @@ typedef unsigned short u_int16_t;
/* /*
* Extended asyncmap - allows any character to be escaped. * Extended asyncmap - allows any character to be escaped.
*/ */
typedef u_int32_t ext_accm[8]; typedef u_char ext_accm[32];
/* /*
* What to do with network protocol (NP) packets. * What to do with network protocol (NP) packets.
@ -407,6 +434,18 @@ extern struct protent *protocols[];
#define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */ #define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
#define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */ #define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
/*
* PPP IOCTL commands.
*/
/*
* Get the up status - 0 for down, non-zero for up. The argument must
* point to an int.
*/
#define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
#define PPPCTLS_ERRCODE 101 /* Set the error code */
#define PPPCTLG_ERRCODE 102 /* Get the error code */
#define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
/************************ /************************
*** PUBLIC DATA TYPES *** *** PUBLIC DATA TYPES ***
************************/ ************************/
@ -503,11 +542,62 @@ void ppp_set_auth(enum pppAuthType authType, const char *user, const char *passw
/* Link status callback function prototype */ /* Link status callback function prototype */
typedef void (*pppLinkStatusCB_fn)(void *ctx, int errCode, void *arg); typedef void (*pppLinkStatusCB_fn)(void *ctx, int errCode, void *arg);
#if PPPOS_SUPPORT
/*
* Open a new PPP connection using the given serial I/O device.
* This initializes the PPP control block but does not
* attempt to negotiate the LCP session.
*
* If this port connects to a modem, the modem connection must be
* established before calling this.
*
* Return a new PPP connection descriptor on success or
* an error code (negative) on failure.
*/
int pppOverSerialOpen(sio_fd_t fd, pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx);
#if !PPP_INPROC_OWNTHREAD
/*
* PPP over Serial: this is the input function to be called for received data.
* If PPP_INPROC_OWNTHREAD==1, a separate input thread using the blocking
* sio_read() is used, so this is deactivated.
*/
void pppos_input(int pd, u_char* data, int len);
#endif /* !PPP_INPROC_OWNTHREAD */
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
/* /*
* Open a new PPP Over Ethernet (PPPOE) connection. * Open a new PPP Over Ethernet (PPPOE) connection.
*/ */
int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const char *concentrator_name, int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const char *concentrator_name,
pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx); pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx);
#endif /* PPPOE_SUPPORT */
/*
* Close a PPP connection and release the descriptor.
* Any outstanding packets in the queues are dropped.
* Return 0 on success, an error code on failure.
*/
int pppClose(int pd);
/*
* Indicate to the PPP process that the line has disconnected.
*/
void pppSigHUP(int pd);
#if LWIP_NETIF_STATUS_CALLBACK
/* Set an lwIP-style status-callback for the selected PPP device */
void ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
/* Set an lwIP-style link-callback for the selected PPP device */
void ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
@ -517,18 +607,24 @@ int ppp_over_ethernet_open(struct netif *ethif, const char *service_name, const
/* PPP flow functions /* PPP flow functions
*/ */
void pppOverEthernetInitFailed(int pd);
u_short pppMTU(int pd);
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
void pppOverEthernetInitFailed(int pd);
/* function called by pppoe.c */ /* function called by pppoe.c */
void ppp_input_over_ethernet(int pd, struct pbuf *pb); void ppp_input_over_ethernet(int pd, struct pbuf *pb);
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
int pppIOCtl(int pd, int cmd, void *arg);
/* FIXME: demystify MTU support */
u_short pppMTU(int pd);
/* function called by all PPP subsystems to send packets */ /* function called by all PPP subsystems to send packets */
int ppp_write(int pd, const u_char *s, int n); int ppp_write(int pd, const u_char *s, int n);
/* functions called by auth.c link_terminated() */
void pppLinkDown(int pd);
void pppLinkTerminated(int pd);
/* merge a pbuf chain into one pbuf */ /* merge a pbuf chain into one pbuf */
struct pbuf * ppp_singlebuf(struct pbuf *p); struct pbuf * ppp_singlebuf(struct pbuf *p);
@ -538,6 +634,9 @@ struct pbuf * ppp_singlebuf(struct pbuf *p);
*/ */
void new_phase(int p); void new_phase(int p);
#if PPPOS_SUPPORT
void ppp_set_xaccm(int unit, ext_accm *accm);
#endif /* PPPOS_SUPPORT */
int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp); int ppp_send_config(int unit, int mtu, u_int32_t accm, int pcomp, int accomp);
int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp); int ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp);