diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 594d18c..ccb4bcb 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -1704,7 +1704,7 @@ pppos_input(ppp_pcb *pcb, u_char *s, int l) } } /* If we haven't started a packet, we need a packet header. */ - next_pbuf = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL); + next_pbuf = pbuf_alloc(PBUF_LINK, 0, PBUF_POOL); if (next_pbuf == NULL) { /* No free buffers. Drop the input packet and let the * higher layers deal with it. Continue processing @@ -1716,15 +1716,27 @@ pppos_input(ppp_pcb *pcb, u_char *s, int l) break; } if (pcrx->in_head == NULL) { - u8_t *payload = next_pbuf->payload; + u8_t *payload; + /* pbuf_header() used below is only trying to put PPP headers + * before the current payload pointer if there is enought space + * in the pbuf to allow that. Therefore we don't care if it fails, + * but if it fail we have to set len to the size used by PPP headers. + */ #if PPP_INPROC_MULTITHREADED + if (pbuf_header(next_pbuf, +sizeof(ppp_pcb*) +sizeof(pcrx->in_protocol))) { + next_pbuf->len += sizeof(ppp_pcb*) + sizeof(pcrx->in_protocol); + } + payload = next_pbuf->payload; *((ppp_pcb**)payload) = pcb; payload += sizeof(ppp_pcb*); - next_pbuf->len += sizeof(ppp_pcb*); +#else /* PPP_INPROC_MULTITHREADED */ + if (pbuf_header(next_pbuf, +sizeof(pcrx->in_protocol))) { + next_pbuf->len += sizeof(pcrx->in_protocol); + } + payload = next_pbuf->payload; #endif /* PPP_INPROC_MULTITHREADED */ *(payload++) = pcrx->in_protocol >> 8; *(payload) = pcrx->in_protocol & 0xFF; - next_pbuf->len += sizeof(pcrx->in_protocol); pcrx->in_head = next_pbuf; } pcrx->in_tail = next_pbuf;