mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-10 16:14:31 +00:00
PPP, added PPP_USE_PBUF_RAM compile time option
pbuf_type PPP is using for LCP, PAP, CHAP, EAP, IPCP and IP6CP packets. Memory allocated must be single buffered for PPP to works, it requires pbuf that are not going to be chained when allocated. This requires setting PBUF_POOL_BUFSIZE to at least 512 bytes, which is quite huge for small systems. Setting PPP_USE_PBUF_RAM to 1 makes PPP use memory from heap where continuous buffers are required, allowing you to use a smaller PBUF_POOL_BUFSIZE.
This commit is contained in:
parent
25f9f55878
commit
2350d941a5
@ -1707,6 +1707,20 @@
|
||||
#define LWIP_PPP_API 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* pbuf_type PPP is using for LCP, PAP, CHAP, EAP, IPCP and IP6CP packets.
|
||||
*
|
||||
* Memory allocated must be single buffered for PPP to works, it requires pbuf
|
||||
* that are not going to be chained when allocated. This requires setting
|
||||
* PBUF_POOL_BUFSIZE to at least 512 bytes, which is quite huge for small systems.
|
||||
*
|
||||
* Setting PPP_USE_PBUF_RAM to 1 makes PPP use memory from heap where continuous
|
||||
* buffers are required, allowing you to use a smaller PBUF_POOL_BUFSIZE.
|
||||
*/
|
||||
#ifndef PPP_USE_PBUF_RAM
|
||||
#define PPP_USE_PBUF_RAM 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PPP_FCS_TABLE: Keep a 256*2 byte table to speed up FCS calculation
|
||||
*/
|
||||
|
@ -58,6 +58,20 @@ typedef unsigned char u_char;
|
||||
#include "ppp.h"
|
||||
#include "pppdebug.h"
|
||||
|
||||
/*
|
||||
* Memory used for control packets.
|
||||
*
|
||||
* PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we
|
||||
* cannot figure out how much we are going to use before filling the buffer.
|
||||
*/
|
||||
#if PPP_USE_PBUF_RAM
|
||||
#define PPP_CTRL_PBUF_TYPE PBUF_RAM
|
||||
#define PPP_CTRL_PBUF_MAX_SIZE 512
|
||||
#else /* PPP_USE_PBUF_RAM */
|
||||
#define PPP_CTRL_PBUF_TYPE PBUF_POOL
|
||||
#define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE
|
||||
#endif /* PPP_USE_PBUF_RAM */
|
||||
|
||||
/*
|
||||
* Limits.
|
||||
*/
|
||||
@ -66,7 +80,6 @@ typedef unsigned char u_char;
|
||||
#define MAXNAMELEN 256 /* max length of hostname or name for auth */
|
||||
#define MAXSECRETLEN 256 /* max length of password or secret */
|
||||
|
||||
|
||||
/*
|
||||
* The basic PPP frame.
|
||||
*/
|
||||
|
@ -231,7 +231,7 @@ static void chap_timeout(void *arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(pcb->chap_server.challenge_pktlen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(pcb->chap_server.challenge_pktlen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -331,7 +331,7 @@ static void chap_handle_response(ppp_pcb *pcb, int id,
|
||||
/* send the response */
|
||||
mlen = strlen(pcb->chap_server.message);
|
||||
len = CHAP_HDRLEN + mlen;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +len), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +len), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -430,7 +430,7 @@ static void chap_respond(ppp_pcb *pcb, int id,
|
||||
char rname[MAXNAMELEN+1];
|
||||
char secret[MAXSECRETLEN+1];
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(RESP_MAX_PKTLEN), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(RESP_MAX_PKTLEN), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
|
@ -258,7 +258,7 @@ static void eap_send_failure(ppp_pcb *pcb) {
|
||||
struct pbuf *p;
|
||||
u_char *outp;
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -289,7 +289,7 @@ static void eap_send_success(ppp_pcb *pcb) {
|
||||
struct pbuf *p;
|
||||
u_char *outp;
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + EAP_HEADERLEN), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -686,7 +686,7 @@ static void eap_send_request(ppp_pcb *pcb) {
|
||||
return;
|
||||
}
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PBUF_POOL_BUFSIZE), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -1048,7 +1048,7 @@ static void eap_send_response(ppp_pcb *pcb, u_char id, u_char typenum, u_char *s
|
||||
int msglen;
|
||||
|
||||
msglen = EAP_HEADERLEN + sizeof (u_char) + lenstr;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -1082,7 +1082,7 @@ static void eap_chap_response(ppp_pcb *pcb, u_char id, u_char *hash, char *name,
|
||||
|
||||
msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + MD5_SIGNATURE_SIZE +
|
||||
namelen;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -1127,7 +1127,7 @@ int lenstr;
|
||||
int msglen;
|
||||
|
||||
msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + lenstr;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -1169,7 +1169,7 @@ u_char *str;
|
||||
|
||||
msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + sizeof (u32_t) +
|
||||
SHA_DIGESTSIZE;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -1200,7 +1200,7 @@ static void eap_send_nak(ppp_pcb *pcb, u_char id, u_char type) {
|
||||
int msglen;
|
||||
|
||||
msglen = EAP_HEADERLEN + 2 * sizeof (u_char);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN + msglen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
|
@ -721,7 +721,7 @@ static void fsm_sconfreq(fsm *f, int retransmit) {
|
||||
} else
|
||||
cilen = 0;
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(cilen + HEADERLEN + PPP_HDRLEN), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(cilen + HEADERLEN + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -763,7 +763,7 @@ void fsm_sdata(fsm *f, u_char code, u_char id, u_char *data, int datalen) {
|
||||
datalen = pcb->peer_mru - HEADERLEN;
|
||||
outlen = datalen + HEADERLEN;
|
||||
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(outlen + PPP_HDRLEN), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(outlen + PPP_HDRLEN), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
|
@ -1780,7 +1780,7 @@ static int lcp_reqci(fsm *f, u_char *inp, int *lenp, int reject_if_disagree) {
|
||||
* Process all his options.
|
||||
*/
|
||||
next = inp;
|
||||
nakp = pbuf_alloc(PBUF_RAW, (u16_t)(PBUF_POOL_BUFSIZE), PBUF_POOL);
|
||||
nakp = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_CTRL_PBUF_MAX_SIZE), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == nakp)
|
||||
return 0;
|
||||
if(nakp->tot_len != nakp->len) {
|
||||
|
@ -527,7 +527,7 @@ static void upap_sauthreq(ppp_pcb *pcb) {
|
||||
|
||||
outlen = UPAP_HEADERLEN + 2 * sizeof (u_char) +
|
||||
pcb->upap.us_userlen + pcb->upap.us_passwdlen;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
@ -564,7 +564,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;
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PBUF_POOL);
|
||||
p = pbuf_alloc(PBUF_RAW, (u16_t)(PPP_HDRLEN +outlen), PPP_CTRL_PBUF_TYPE);
|
||||
if(NULL == p)
|
||||
return;
|
||||
if(p->tot_len != p->len) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user