mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-03 21:14:40 +08:00
Fixes bug #13807: slipif_input() garbles large (i.e. multiple pbufs) inbound datagrams.
This commit is contained in:
parent
baf377679a
commit
e11d57c883
@ -32,9 +32,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is an arch independent SLIP netif. The specific serial hooks must be provided
|
* This is an arch independent SLIP netif. The specific serial hooks must be
|
||||||
* by another file.They are sio_open, sio_recv and sio_send
|
* provided by another file. They are sio_open, sio_recv and sio_send
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "netif/slipif.h"
|
#include "netif/slipif.h"
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
@ -55,7 +55,7 @@
|
|||||||
* Send a pbuf doing the necessary SLIP encapsulation
|
* Send a pbuf doing the necessary SLIP encapsulation
|
||||||
*
|
*
|
||||||
* Uses the serial layer's sio_send()
|
* Uses the serial layer's sio_send()
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t
|
||||||
slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
|
slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
|
||||||
{
|
{
|
||||||
@ -66,21 +66,21 @@ slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
|
|||||||
/* Send pbuf out on the serial I/O device. */
|
/* Send pbuf out on the serial I/O device. */
|
||||||
sio_send(SLIP_END, netif->state);
|
sio_send(SLIP_END, netif->state);
|
||||||
|
|
||||||
for(q = p; q != NULL; q = q->next) {
|
for (q = p; q != NULL; q = q->next) {
|
||||||
for(i = 0; i < q->len; i++) {
|
for (i = 0; i < q->len; i++) {
|
||||||
c = ((u8_t *)q->payload)[i];
|
c = ((u8_t *)q->payload)[i];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case SLIP_END:
|
case SLIP_END:
|
||||||
sio_send(SLIP_ESC, netif->state);
|
sio_send(SLIP_ESC, netif->state);
|
||||||
sio_send(SLIP_ESC_END, netif->state);
|
sio_send(SLIP_ESC_END, netif->state);
|
||||||
break;
|
break;
|
||||||
case SLIP_ESC:
|
case SLIP_ESC:
|
||||||
sio_send(SLIP_ESC, netif->state);
|
sio_send(SLIP_ESC, netif->state);
|
||||||
sio_send(SLIP_ESC_ESC, netif->state);
|
sio_send(SLIP_ESC_ESC, netif->state);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sio_send(c, netif->state);
|
sio_send(c, netif->state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,9 +94,9 @@ slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
|
|||||||
* Poll the serial layer by calling sio_recv()
|
* Poll the serial layer by calling sio_recv()
|
||||||
*
|
*
|
||||||
* @return The IP packet when SLIP_END is received
|
* @return The IP packet when SLIP_END is received
|
||||||
*/
|
*/
|
||||||
static struct pbuf *
|
static struct pbuf *
|
||||||
slipif_input( struct netif * netif )
|
slipif_input(struct netif *netif)
|
||||||
{
|
{
|
||||||
u8_t c;
|
u8_t c;
|
||||||
struct pbuf *p, *q;
|
struct pbuf *p, *q;
|
||||||
@ -112,13 +112,13 @@ slipif_input( struct netif * netif )
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case SLIP_END:
|
case SLIP_END:
|
||||||
if (recved > 0) {
|
if (recved > 0) {
|
||||||
/* Received whole packet. */
|
/* Received whole packet. */
|
||||||
pbuf_realloc(q, recved);
|
pbuf_realloc(q, recved);
|
||||||
|
|
||||||
LINK_STATS_INC(link.recv);
|
LINK_STATS_INC(link.recv);
|
||||||
|
|
||||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
|
LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -126,42 +126,45 @@ slipif_input( struct netif * netif )
|
|||||||
c = sio_recv(netif->state);
|
c = sio_recv(netif->state);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case SLIP_ESC_END:
|
case SLIP_ESC_END:
|
||||||
c = SLIP_END;
|
c = SLIP_END;
|
||||||
break;
|
break;
|
||||||
case SLIP_ESC_ESC:
|
case SLIP_ESC_ESC:
|
||||||
c = SLIP_ESC;
|
c = SLIP_ESC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
|
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
|
||||||
p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
|
p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
|
||||||
|
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
LINK_STATS_INC(link.drop);
|
LINK_STATS_INC(link.drop);
|
||||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
|
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
pbuf_cat(q, p);
|
pbuf_cat(q, p);
|
||||||
} else {
|
} else {
|
||||||
q = p;
|
q = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p != NULL && recved < MAX_SIZE) {
|
if (p != NULL && recved < MAX_SIZE) {
|
||||||
((u8_t *)p->payload)[i] = c;
|
((u8_t *)p->payload)[i] = c;
|
||||||
recved++;
|
recved++;
|
||||||
i++;
|
i++;
|
||||||
if (i >= p->len) {
|
if (i >= p->len) {
|
||||||
i = 0;
|
i = 0;
|
||||||
p = NULL;
|
if (p->next != NULL && p->next->len > 0)
|
||||||
}
|
p = p->next;
|
||||||
|
else
|
||||||
|
p = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -170,7 +173,7 @@ slipif_input( struct netif * netif )
|
|||||||
* The SLIP input thread
|
* The SLIP input thread
|
||||||
*
|
*
|
||||||
* Feed the IP layer with incoming packets
|
* Feed the IP layer with incoming packets
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
slipif_loop(void *nf)
|
slipif_loop(void *nf)
|
||||||
{
|
{
|
||||||
@ -188,22 +191,22 @@ slipif_loop(void *nf)
|
|||||||
*
|
*
|
||||||
* Call the arch specific sio_open and remember
|
* Call the arch specific sio_open and remember
|
||||||
* the opened device in the state field of the netif.
|
* the opened device in the state field of the netif.
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t
|
||||||
slipif_init(struct netif *netif)
|
slipif_init(struct netif *netif)
|
||||||
{
|
{
|
||||||
|
|
||||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%x\n", (int)netif->num));
|
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%x\n", (int)netif->num));
|
||||||
|
|
||||||
netif->name[0] = 's';
|
netif->name[0] = 's';
|
||||||
netif->name[1] = 'l';
|
netif->name[1] = 'l';
|
||||||
netif->output = slipif_output;
|
netif->output = slipif_output;
|
||||||
netif->mtu = 1500;
|
netif->mtu = 1500;
|
||||||
netif->flags = NETIF_FLAG_POINTTOPOINT;
|
netif->flags = NETIF_FLAG_POINTTOPOINT;
|
||||||
|
|
||||||
netif->state = sio_open(netif->num);
|
netif->state = sio_open(netif->num);
|
||||||
if (!netif->state)
|
if (!netif->state)
|
||||||
return ERR_IF;
|
return ERR_IF;
|
||||||
|
|
||||||
sys_thread_new(slipif_loop, netif, SLIPIF_THREAD_PRIO);
|
sys_thread_new(slipif_loop, netif, SLIPIF_THREAD_PRIO);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user