Fixes bug #13807: slipif_input() garbles large (i.e. multiple pbufs) inbound datagrams.

This commit is contained in:
likewise 2005-07-17 15:13:34 +00:00
parent baf377679a
commit e11d57c883

View File

@ -32,8 +32,8 @@
*/
/*
* This is an arch independent SLIP netif. The specific serial hooks must be provided
* by another file.They are sio_open, sio_recv and sio_send
* This is an arch independent SLIP netif. The specific serial hooks must be
* provided by another file. They are sio_open, sio_recv and sio_send
*/
#include "netif/slipif.h"
@ -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. */
sio_send(SLIP_END, netif->state);
for(q = p; q != NULL; q = q->next) {
for(i = 0; i < q->len; i++) {
for (q = p; q != NULL; q = q->next) {
for (i = 0; i < q->len; i++) {
c = ((u8_t *)q->payload)[i];
switch (c) {
case SLIP_END:
sio_send(SLIP_ESC, netif->state);
sio_send(SLIP_ESC_END, netif->state);
break;
sio_send(SLIP_ESC, netif->state);
sio_send(SLIP_ESC_END, netif->state);
break;
case SLIP_ESC:
sio_send(SLIP_ESC, netif->state);
sio_send(SLIP_ESC_ESC, netif->state);
break;
sio_send(SLIP_ESC, netif->state);
sio_send(SLIP_ESC_ESC, netif->state);
break;
default:
sio_send(c, netif->state);
break;
sio_send(c, netif->state);
break;
}
}
}
@ -96,7 +96,7 @@ slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
* @return The IP packet when SLIP_END is received
*/
static struct pbuf *
slipif_input( struct netif * netif )
slipif_input(struct netif *netif)
{
u8_t c;
struct pbuf *p, *q;
@ -112,13 +112,13 @@ slipif_input( struct netif * netif )
switch (c) {
case SLIP_END:
if (recved > 0) {
/* Received whole packet. */
pbuf_realloc(q, recved);
/* Received whole packet. */
pbuf_realloc(q, recved);
LINK_STATS_INC(link.recv);
LINK_STATS_INC(link.recv);
LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
return q;
LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
return q;
}
break;
@ -126,38 +126,41 @@ slipif_input( struct netif * netif )
c = sio_recv(netif->state);
switch (c) {
case SLIP_ESC_END:
c = SLIP_END;
break;
c = SLIP_END;
break;
case SLIP_ESC_ESC:
c = SLIP_ESC;
break;
c = SLIP_ESC;
break;
}
/* FALLTHROUGH */
default:
if (p == NULL) {
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
if (p == NULL) {
LINK_STATS_INC(link.drop);
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
}
if (p == NULL) {
LINK_STATS_INC(link.drop);
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
}
if (q != NULL) {
pbuf_cat(q, p);
} else {
q = p;
}
if (q != NULL) {
pbuf_cat(q, p);
} else {
q = p;
}
}
if (p != NULL && recved < MAX_SIZE) {
((u8_t *)p->payload)[i] = c;
recved++;
i++;
if (i >= p->len) {
i = 0;
p = NULL;
}
((u8_t *)p->payload)[i] = c;
recved++;
i++;
if (i >= p->len) {
i = 0;
if (p->next != NULL && p->next->len > 0)
p = p->next;
else
p = NULL;
}
}
break;
}
@ -203,7 +206,7 @@ slipif_init(struct netif *netif)
netif->state = sio_open(netif->num);
if (!netif->state)
return ERR_IF;
return ERR_IF;
sys_thread_new(slipif_loop, netif, SLIPIF_THREAD_PRIO);
return ERR_OK;