Major stylo search/replace for "One space between keyword and opening bracket."

This commit is contained in:
likewise 2003-05-01 13:24:01 +00:00
parent 4c3f44b0d2
commit 03bc7c868b
27 changed files with 624 additions and 601 deletions

View File

@ -4,6 +4,8 @@ HISTORY
++ Changes: ++ Changes:
* Now drops short packets for ICMP/UDP/TCP protocols. More robust.
* ARP queueuing now queues the latest packet instead of the first. * ARP queueuing now queues the latest packet instead of the first.
This is the recommended behaviour, but can be overridden in This is the recommended behaviour, but can be overridden in
lwipopts.h. lwipopts.h.

View File

@ -8,29 +8,36 @@ features of Savannah help us not lose users' input.
Source code style: Source code style:
- indentation is two spaces per level, no tabs. - do not use tabs.
- indentation is two spaces per level.
- end debug messages with a trailing newline (\n). - end debug messages with a trailing newline (\n).
- no space between function and opening bracket.
- one space between keyword and opening bracket. - one space between keyword and opening bracket.
- one space and no newline before opening curly braces. - no space between function and opening bracket.
- one space and no newline before opening curly braces of a block.
- spaces surrounding assignment and comparisons. - spaces surrounding assignment and comparisons.
- use current source code style as further reference. - use current source code style as further reference.
Source code self documentation style: Source code documentation style:
- JavaDoc compliant and Doxygen compatible. - JavaDoc compliant and Doxygen compatible.
- Function documentation above functions in .c files, not .h files. - Function documentation above functions in .c files, not .h files.
(This forces you to synchronize documentation and behaviour.)
- Use current documentation style as further reference. - Use current documentation style as further reference.
Bug reports and patches: Bug reports and patches:
- Make sure you are reporting bugs or send patches against the latest sources.That usually means code in CVS - Make sure you are reporting bugs or send patches against the latest
- If you think you found a bug make sure it's not already filed in the bugtracker at savannah sources. (From the latest release and/or the current CVS sources.)
- If you have a fix put the patch on Savannah. If it's a patch that affects both core and arch specific - If you think you found a bug make sure it's not already filed in the
stuff please separate them so that the core can be applied separately while leaving the other patch 'open' bugtracker at Savannah.
The prefered way is to NOT touch archs you can't test and let maintainers take care of them. This is a good - If you have a fix put the patch on Savannah. If it is a patch that affects
way to see if they are used at all - the same goes for unix netifs except tapif. both core and arch specific stuff please separate them so that the core can
- Do not file a bug and post a fix to it to the patch area. Either a bug report or a patch will be enough. be applied separately while leaving the other patch 'open'. The prefered way
is to NOT touch archs you can't test and let maintainers take care of them.
This is a good way to see if they are used at all - the same goes for unix
netifs except tapif.
- Do not file a bug and post a fix to it to the patch area. Either a bug report
or a patch will be enough.
If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area. If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area.
- Trivial patches (compiler warning, indentation and spelling fixes or anything obvious which takes a line or two) - Trivial patches (compiler warning, indentation and spelling fixes or anything obvious which takes a line or two)
can go to the lwip-users list. This is still the fastest way of interaction and the list is not so crowded can go to the lwip-users list. This is still the fastest way of interaction and the list is not so crowded

View File

@ -45,7 +45,7 @@ netbuf *netbuf_new(void)
struct netbuf *buf; struct netbuf *buf;
buf = memp_mallocp(MEMP_NETBUF); buf = memp_mallocp(MEMP_NETBUF);
if(buf != NULL) { if (buf != NULL) {
buf->p = NULL; buf->p = NULL;
buf->ptr = NULL; buf->ptr = NULL;
return buf; return buf;
@ -57,8 +57,8 @@ netbuf *netbuf_new(void)
void void
netbuf_delete(struct netbuf *buf) netbuf_delete(struct netbuf *buf)
{ {
if(buf != NULL) { if (buf != NULL) {
if(buf->p != NULL) { if (buf->p != NULL) {
pbuf_free(buf->p); pbuf_free(buf->p);
buf->p = buf->ptr = NULL; buf->p = buf->ptr = NULL;
} }
@ -70,11 +70,11 @@ void *
netbuf_alloc(struct netbuf *buf, u16_t size) netbuf_alloc(struct netbuf *buf, u16_t size)
{ {
/* Deallocate any previously allocated memory. */ /* Deallocate any previously allocated memory. */
if(buf->p != NULL) { if (buf->p != NULL) {
pbuf_free(buf->p); pbuf_free(buf->p);
} }
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
if(buf->p == NULL) { if (buf->p == NULL) {
return NULL; return NULL;
} }
buf->ptr = buf->p; buf->ptr = buf->p;
@ -84,7 +84,7 @@ netbuf_alloc(struct netbuf *buf, u16_t size)
void void
netbuf_free(struct netbuf *buf) netbuf_free(struct netbuf *buf)
{ {
if(buf->p != NULL) { if (buf->p != NULL) {
pbuf_free(buf->p); pbuf_free(buf->p);
} }
buf->p = buf->ptr = NULL; buf->p = buf->ptr = NULL;
@ -93,7 +93,7 @@ netbuf_free(struct netbuf *buf)
void void
netbuf_ref(struct netbuf *buf, void *dataptr, u16_t size) netbuf_ref(struct netbuf *buf, void *dataptr, u16_t size)
{ {
if(buf->p != NULL) { if (buf->p != NULL) {
pbuf_free(buf->p); pbuf_free(buf->p);
} }
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
@ -119,7 +119,7 @@ netbuf_len(struct netbuf *buf)
err_t err_t
netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len) netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
{ {
if(buf->ptr == NULL) { if (buf->ptr == NULL) {
return ERR_BUF; return ERR_BUF;
} }
*dataptr = buf->ptr->payload; *dataptr = buf->ptr->payload;
@ -130,11 +130,11 @@ netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
s8_t s8_t
netbuf_next(struct netbuf *buf) netbuf_next(struct netbuf *buf)
{ {
if(buf->ptr->next == NULL) { if (buf->ptr->next == NULL) {
return -1; return -1;
} }
buf->ptr = buf->ptr->next; buf->ptr = buf->ptr->next;
if(buf->ptr->next == NULL) { if (buf->ptr->next == NULL) {
return 1; return 1;
} }
return 0; return 0;
@ -154,19 +154,19 @@ netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
left = 0; left = 0;
if(buf == NULL) { if (buf == NULL) {
return; return;
} }
/* This implementation is bad. It should use bcopy /* This implementation is bad. It should use bcopy
instead. */ instead. */
for(p = buf->p; left < len && p != NULL; p = p->next) { for(p = buf->p; left < len && p != NULL; p = p->next) {
if(offset != 0 && offset >= p->len) { if (offset != 0 && offset >= p->len) {
offset -= p->len; offset -= p->len;
} else { } else {
for(i = offset; i < p->len; ++i) { for(i = offset; i < p->len; ++i) {
((char *)dataptr)[left] = ((char *)p->payload)[i]; ((char *)dataptr)[left] = ((char *)p->payload)[i];
if(++left >= len) { if (++left >= len) {
return; return;
} }
} }
@ -199,13 +199,13 @@ netconn *netconn_new(enum netconn_type t)
struct netconn *conn; struct netconn *conn;
conn = memp_mallocp(MEMP_NETCONN); conn = memp_mallocp(MEMP_NETCONN);
if(conn == NULL) { if (conn == NULL) {
return NULL; return NULL;
} }
conn->type = t; conn->type = t;
conn->pcb.tcp = NULL; conn->pcb.tcp = NULL;
if((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
memp_freep(MEMP_NETCONN, conn); memp_freep(MEMP_NETCONN, conn);
return NULL; return NULL;
} }
@ -239,11 +239,11 @@ netconn_delete(struct netconn *conn)
struct api_msg *msg; struct api_msg *msg;
void *mem; void *mem;
if(conn == NULL) { if (conn == NULL) {
return ERR_OK; return ERR_OK;
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
@ -254,9 +254,9 @@ netconn_delete(struct netconn *conn)
memp_freep(MEMP_API_MSG, msg); memp_freep(MEMP_API_MSG, msg);
/* Drain the recvmbox. */ /* Drain the recvmbox. */
if(conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
while(sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != SYS_ARCH_TIMEOUT) { while (sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != SYS_ARCH_TIMEOUT) {
if(conn->type == NETCONN_TCP) { if (conn->type == NETCONN_TCP) {
pbuf_free((struct pbuf *)mem); pbuf_free((struct pbuf *)mem);
} else { } else {
netbuf_delete((struct netbuf *)mem); netbuf_delete((struct netbuf *)mem);
@ -268,8 +268,8 @@ netconn_delete(struct netconn *conn)
/* Drain the acceptmbox. */ /* Drain the acceptmbox. */
if(conn->acceptmbox != SYS_MBOX_NULL) { if (conn->acceptmbox != SYS_MBOX_NULL) {
while(sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != SYS_ARCH_TIMEOUT) { while (sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != SYS_ARCH_TIMEOUT) {
netconn_delete((struct netconn *)mem); netconn_delete((struct netconn *)mem);
} }
@ -279,7 +279,7 @@ netconn_delete(struct netconn *conn)
sys_mbox_free(conn->mbox); sys_mbox_free(conn->mbox);
conn->mbox = SYS_MBOX_NULL; conn->mbox = SYS_MBOX_NULL;
if(conn->sem != SYS_SEM_NULL) { if (conn->sem != SYS_SEM_NULL) {
sys_sem_free(conn->sem); sys_sem_free(conn->sem);
} }
/* conn->sem = SYS_SEM_NULL;*/ /* conn->sem = SYS_SEM_NULL;*/
@ -297,7 +297,7 @@ err_t
netconn_peer(struct netconn *conn, struct ip_addr *addr, netconn_peer(struct netconn *conn, struct ip_addr *addr,
u16_t *port) u16_t *port)
{ {
switch(conn->type) { switch (conn->type) {
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM: case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP: case NETCONN_UDP:
@ -308,7 +308,7 @@ netconn_peer(struct netconn *conn, struct ip_addr *addr,
*port = conn->pcb.udp->remote_port; *port = conn->pcb.udp->remote_port;
break; break;
case NETCONN_TCP: case NETCONN_TCP:
if(conn->pcb.tcp == NULL) if (conn->pcb.tcp == NULL)
return ERR_CONN; return ERR_CONN;
*addr = (conn->pcb.tcp->remote_ip); *addr = (conn->pcb.tcp->remote_ip);
*port = conn->pcb.tcp->remote_port; *port = conn->pcb.tcp->remote_port;
@ -321,7 +321,7 @@ err_t
netconn_addr(struct netconn *conn, struct ip_addr **addr, netconn_addr(struct netconn *conn, struct ip_addr **addr,
u16_t *port) u16_t *port)
{ {
switch(conn->type) { switch (conn->type) {
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM: case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP: case NETCONN_UDP:
@ -342,18 +342,18 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr,
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if(conn->type != NETCONN_TCP && if (conn->type != NETCONN_TCP &&
conn->recvmbox == SYS_MBOX_NULL) { conn->recvmbox == SYS_MBOX_NULL) {
if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
return ERR_MEM; return ERR_MEM;
} }
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_BIND; msg->type = API_MSG_BIND;
@ -373,18 +373,18 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr,
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if(conn->recvmbox == SYS_MBOX_NULL) { if (conn->recvmbox == SYS_MBOX_NULL) {
if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
return ERR_MEM; return ERR_MEM;
} }
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
msg->type = API_MSG_CONNECT; msg->type = API_MSG_CONNECT;
@ -402,11 +402,11 @@ netconn_disconnect(struct netconn *conn)
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
msg->type = API_MSG_DISCONNECT; msg->type = API_MSG_DISCONNECT;
@ -423,18 +423,18 @@ netconn_listen(struct netconn *conn)
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if(conn->acceptmbox == SYS_MBOX_NULL) { if (conn->acceptmbox == SYS_MBOX_NULL) {
conn->acceptmbox = sys_mbox_new(); conn->acceptmbox = sys_mbox_new();
if(conn->acceptmbox == SYS_MBOX_NULL) { if (conn->acceptmbox == SYS_MBOX_NULL) {
return ERR_MEM; return ERR_MEM;
} }
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_LISTEN; msg->type = API_MSG_LISTEN;
@ -450,7 +450,7 @@ netconn_accept(struct netconn *conn)
{ {
struct netconn *newconn; struct netconn *newconn;
if(conn == NULL) { if (conn == NULL) {
return NULL; return NULL;
} }
@ -470,21 +470,21 @@ netconn_recv(struct netconn *conn)
struct pbuf *p; struct pbuf *p;
u16_t len; u16_t len;
if(conn == NULL) { if (conn == NULL) {
return NULL; return NULL;
} }
if(conn->recvmbox == SYS_MBOX_NULL) { if (conn->recvmbox == SYS_MBOX_NULL) {
conn->err = ERR_CONN; conn->err = ERR_CONN;
return NULL; return NULL;
} }
if(conn->err != ERR_OK) { if (conn->err != ERR_OK) {
return NULL; return NULL;
} }
if(conn->type == NETCONN_TCP) { if (conn->type == NETCONN_TCP) {
if(conn->pcb.tcp->state == LISTEN) { if (conn->pcb.tcp->state == LISTEN) {
conn->err = ERR_CONN; conn->err = ERR_CONN;
return NULL; return NULL;
} }
@ -492,7 +492,7 @@ netconn_recv(struct netconn *conn)
buf = memp_mallocp(MEMP_NETBUF); buf = memp_mallocp(MEMP_NETBUF);
if(buf == NULL) { if (buf == NULL) {
conn->err = ERR_MEM; conn->err = ERR_MEM;
return NULL; return NULL;
} }
@ -513,7 +513,7 @@ netconn_recv(struct netconn *conn)
/* If we are closed, we indicate that we no longer wish to recieve /* If we are closed, we indicate that we no longer wish to recieve
data by setting conn->recvmbox to SYS_MBOX_NULL. */ data by setting conn->recvmbox to SYS_MBOX_NULL. */
if(p == NULL) { if (p == NULL) {
memp_freep(MEMP_NETBUF, buf); memp_freep(MEMP_NETBUF, buf);
sys_mbox_free(conn->recvmbox); sys_mbox_free(conn->recvmbox);
conn->recvmbox = SYS_MBOX_NULL; conn->recvmbox = SYS_MBOX_NULL;
@ -526,13 +526,13 @@ netconn_recv(struct netconn *conn)
buf->fromaddr = NULL; buf->fromaddr = NULL;
/* Let the stack know that we have taken the data. */ /* Let the stack know that we have taken the data. */
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
conn->err = ERR_MEM; conn->err = ERR_MEM;
return buf; return buf;
} }
msg->type = API_MSG_RECV; msg->type = API_MSG_RECV;
msg->msg.conn = conn; msg->msg.conn = conn;
if(buf != NULL) { if (buf != NULL) {
msg->msg.msg.len = buf->p->tot_len; msg->msg.msg.len = buf->p->tot_len;
} else { } else {
msg->msg.msg.len = 1; msg->msg.msg.len = 1;
@ -563,15 +563,15 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if(conn->err != ERR_OK) { if (conn->err != ERR_OK) {
return conn->err; return conn->err;
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
@ -592,22 +592,22 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
struct api_msg *msg; struct api_msg *msg;
u16_t len; u16_t len;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if(conn->err != ERR_OK) { if (conn->err != ERR_OK) {
return conn->err; return conn->err;
} }
if(conn->sem == SYS_SEM_NULL) { if (conn->sem == SYS_SEM_NULL) {
conn->sem = sys_sem_new(0); conn->sem = sys_sem_new(0);
if(conn->sem == SYS_SEM_NULL) { if (conn->sem == SYS_SEM_NULL) {
return ERR_MEM; return ERR_MEM;
} }
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_WRITE; msg->type = API_MSG_WRITE;
@ -615,18 +615,18 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
conn->state = NETCONN_WRITE; conn->state = NETCONN_WRITE;
while(conn->err == ERR_OK && size > 0) { while (conn->err == ERR_OK && size > 0) {
msg->msg.msg.w.dataptr = dataptr; msg->msg.msg.w.dataptr = dataptr;
msg->msg.msg.w.copy = copy; msg->msg.msg.w.copy = copy;
if(conn->type == NETCONN_TCP) { if (conn->type == NETCONN_TCP) {
if(tcp_sndbuf(conn->pcb.tcp) == 0) { if (tcp_sndbuf(conn->pcb.tcp) == 0) {
sys_sem_wait(conn->sem); sys_sem_wait(conn->sem);
if(conn->err != ERR_OK) { if (conn->err != ERR_OK) {
goto ret; goto ret;
} }
} }
if(size > tcp_sndbuf(conn->pcb.tcp)) { if (size > tcp_sndbuf(conn->pcb.tcp)) {
/* We cannot send more than one send buffer's worth of data at a /* We cannot send more than one send buffer's worth of data at a
time. */ time. */
len = tcp_sndbuf(conn->pcb.tcp); len = tcp_sndbuf(conn->pcb.tcp);
@ -641,10 +641,10 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
msg->msg.msg.w.len = len; msg->msg.msg.w.len = len;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
if(conn->err == ERR_OK) { if (conn->err == ERR_OK) {
dataptr = (void *)((char *)dataptr + len); dataptr = (void *)((char *)dataptr + len);
size -= len; size -= len;
} else if(conn->err == ERR_MEM) { } else if (conn->err == ERR_MEM) {
conn->err = ERR_OK; conn->err = ERR_OK;
sys_sem_wait(conn->sem); sys_sem_wait(conn->sem);
} else { } else {
@ -654,7 +654,7 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
ret: ret:
memp_freep(MEMP_API_MSG, msg); memp_freep(MEMP_API_MSG, msg);
conn->state = NETCONN_NONE; conn->state = NETCONN_NONE;
if(conn->sem != SYS_SEM_NULL) { if (conn->sem != SYS_SEM_NULL) {
sys_sem_free(conn->sem); sys_sem_free(conn->sem);
conn->sem = SYS_SEM_NULL; conn->sem = SYS_SEM_NULL;
} }
@ -667,10 +667,10 @@ netconn_close(struct netconn *conn)
{ {
struct api_msg *msg; struct api_msg *msg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
@ -680,7 +680,7 @@ netconn_close(struct netconn *conn)
msg->msg.conn = conn; msg->msg.conn = conn;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
if(conn->err == ERR_MEM && if (conn->err == ERR_MEM &&
conn->sem != SYS_SEM_NULL) { conn->sem != SYS_SEM_NULL) {
sys_sem_wait(conn->sem); sys_sem_wait(conn->sem);
goto again; goto again;

View File

@ -47,13 +47,13 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
conn = arg; conn = arg;
if(conn == NULL) { if (conn == NULL) {
pbuf_free(p); pbuf_free(p);
return; return;
} }
if(conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
buf = memp_mallocp(MEMP_NETBUF); buf = memp_mallocp(MEMP_NETBUF);
if(buf == NULL) { if (buf == NULL) {
pbuf_free(p); pbuf_free(p);
return; return;
} else { } else {
@ -81,12 +81,12 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
conn = arg; conn = arg;
if(conn == NULL) { if (conn == NULL) {
pbuf_free(p); pbuf_free(p);
return ERR_VAL; return ERR_VAL;
} }
if(conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
conn->err = err; conn->err = err;
if (p != NULL) { if (p != NULL) {
@ -110,7 +110,7 @@ poll_tcp(void *arg, struct tcp_pcb *pcb)
struct netconn *conn; struct netconn *conn;
conn = arg; conn = arg;
if(conn != NULL && if (conn != NULL &&
(conn->state == NETCONN_WRITE || conn->state == NETCONN_CLOSE) && (conn->state == NETCONN_WRITE || conn->state == NETCONN_CLOSE) &&
conn->sem != SYS_SEM_NULL) { conn->sem != SYS_SEM_NULL) {
sys_sem_signal(conn->sem); sys_sem_signal(conn->sem);
@ -124,7 +124,7 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
struct netconn *conn; struct netconn *conn;
conn = arg; conn = arg;
if(conn != NULL && conn->sem != SYS_SEM_NULL) { if (conn != NULL && conn->sem != SYS_SEM_NULL) {
sys_sem_signal(conn->sem); sys_sem_signal(conn->sem);
} }
@ -146,22 +146,22 @@ err_tcp(void *arg, err_t err)
conn->err = err; conn->err = err;
if(conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
/* Register event with callback */ /* Register event with callback */
if (conn->callback) if (conn->callback)
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0); (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
sys_mbox_post(conn->recvmbox, NULL); sys_mbox_post(conn->recvmbox, NULL);
} }
if(conn->mbox != SYS_MBOX_NULL) { if (conn->mbox != SYS_MBOX_NULL) {
sys_mbox_post(conn->mbox, NULL); sys_mbox_post(conn->mbox, NULL);
} }
if(conn->acceptmbox != SYS_MBOX_NULL) { if (conn->acceptmbox != SYS_MBOX_NULL) {
/* Register event with callback */ /* Register event with callback */
if (conn->callback) if (conn->callback)
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0); (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
sys_mbox_post(conn->acceptmbox, NULL); sys_mbox_post(conn->acceptmbox, NULL);
} }
if(conn->sem != SYS_SEM_NULL) { if (conn->sem != SYS_SEM_NULL) {
sys_sem_signal(conn->sem); sys_sem_signal(conn->sem);
} }
} }
@ -194,25 +194,25 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
conn = (struct netconn *)arg; conn = (struct netconn *)arg;
mbox = conn->acceptmbox; mbox = conn->acceptmbox;
newconn = memp_mallocp(MEMP_NETCONN); newconn = memp_mallocp(MEMP_NETCONN);
if(newconn == NULL) { if (newconn == NULL) {
return ERR_MEM; return ERR_MEM;
} }
newconn->type = NETCONN_TCP; newconn->type = NETCONN_TCP;
newconn->pcb.tcp = newpcb; newconn->pcb.tcp = newpcb;
setup_tcp(newconn); setup_tcp(newconn);
newconn->recvmbox = sys_mbox_new(); newconn->recvmbox = sys_mbox_new();
if(newconn->recvmbox == SYS_MBOX_NULL) { if (newconn->recvmbox == SYS_MBOX_NULL) {
memp_free(MEMP_NETCONN, newconn); memp_free(MEMP_NETCONN, newconn);
return ERR_MEM; return ERR_MEM;
} }
newconn->mbox = sys_mbox_new(); newconn->mbox = sys_mbox_new();
if(newconn->mbox == SYS_MBOX_NULL) { if (newconn->mbox == SYS_MBOX_NULL) {
sys_mbox_free(newconn->recvmbox); sys_mbox_free(newconn->recvmbox);
memp_free(MEMP_NETCONN, newconn); memp_free(MEMP_NETCONN, newconn);
return ERR_MEM; return ERR_MEM;
} }
newconn->sem = sys_sem_new(0); newconn->sem = sys_sem_new(0);
if(newconn->sem == SYS_SEM_NULL) { if (newconn->sem == SYS_SEM_NULL) {
sys_mbox_free(newconn->recvmbox); sys_mbox_free(newconn->recvmbox);
sys_mbox_free(newconn->mbox); sys_mbox_free(newconn->mbox);
memp_free(MEMP_NETCONN, newconn); memp_free(MEMP_NETCONN, newconn);
@ -243,8 +243,8 @@ do_newconn(struct api_msg_msg *msg)
static void static void
do_delconn(struct api_msg_msg *msg) do_delconn(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -257,7 +257,7 @@ do_delconn(struct api_msg_msg *msg)
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
#if LWIP_TCP #if LWIP_TCP
case NETCONN_TCP: case NETCONN_TCP:
if(msg->conn->pcb.tcp->state == LISTEN) { if (msg->conn->pcb.tcp->state == LISTEN) {
tcp_arg(msg->conn->pcb.tcp, NULL); tcp_arg(msg->conn->pcb.tcp, NULL);
tcp_accept(msg->conn->pcb.tcp, NULL); tcp_accept(msg->conn->pcb.tcp, NULL);
tcp_close(msg->conn->pcb.tcp); tcp_close(msg->conn->pcb.tcp);
@ -267,7 +267,7 @@ do_delconn(struct api_msg_msg *msg)
tcp_recv(msg->conn->pcb.tcp, NULL); tcp_recv(msg->conn->pcb.tcp, NULL);
tcp_poll(msg->conn->pcb.tcp, NULL, 0); tcp_poll(msg->conn->pcb.tcp, NULL, 0);
tcp_err(msg->conn->pcb.tcp, NULL); tcp_err(msg->conn->pcb.tcp, NULL);
if(tcp_close(msg->conn->pcb.tcp) != ERR_OK) { if (tcp_close(msg->conn->pcb.tcp) != ERR_OK) {
tcp_abort(msg->conn->pcb.tcp); tcp_abort(msg->conn->pcb.tcp);
} }
} }
@ -283,7 +283,7 @@ do_delconn(struct api_msg_msg *msg)
(*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDPLUS, 0); (*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDPLUS, 0);
} }
if(msg->conn->mbox != SYS_MBOX_NULL) { if (msg->conn->mbox != SYS_MBOX_NULL) {
sys_mbox_post(msg->conn->mbox, NULL); sys_mbox_post(msg->conn->mbox, NULL);
} }
} }
@ -291,8 +291,8 @@ do_delconn(struct api_msg_msg *msg)
static void static void
do_bind(struct api_msg_msg *msg) do_bind(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp == NULL) { if (msg->conn->pcb.tcp == NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
msg->conn->pcb.udp = udp_new(); msg->conn->pcb.udp = udp_new();
@ -318,7 +318,7 @@ do_bind(struct api_msg_msg *msg)
break; break;
} }
} }
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -347,12 +347,12 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
conn = arg; conn = arg;
if(conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
conn->err = err; conn->err = err;
if(conn->type == NETCONN_TCP && err == ERR_OK) { if (conn->type == NETCONN_TCP && err == ERR_OK) {
setup_tcp(conn); setup_tcp(conn);
} }
sys_mbox_post(conn->mbox, NULL); sys_mbox_post(conn->mbox, NULL);
@ -363,12 +363,12 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
static void static void
do_connect(struct api_msg_msg *msg) do_connect(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp == NULL) { if (msg->conn->pcb.tcp == NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
msg->conn->pcb.udp = udp_new(); msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) { if (msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
sys_mbox_post(msg->conn->mbox, NULL); sys_mbox_post(msg->conn->mbox, NULL);
return; return;
@ -378,7 +378,7 @@ do_connect(struct api_msg_msg *msg)
break; break;
case NETCONN_UDPNOCHKSUM: case NETCONN_UDPNOCHKSUM:
msg->conn->pcb.udp = udp_new(); msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) { if (msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
sys_mbox_post(msg->conn->mbox, NULL); sys_mbox_post(msg->conn->mbox, NULL);
return; return;
@ -388,7 +388,7 @@ do_connect(struct api_msg_msg *msg)
break; break;
case NETCONN_UDP: case NETCONN_UDP:
msg->conn->pcb.udp = udp_new(); msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) { if (msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
sys_mbox_post(msg->conn->mbox, NULL); sys_mbox_post(msg->conn->mbox, NULL);
return; return;
@ -399,7 +399,7 @@ do_connect(struct api_msg_msg *msg)
#if LWIP_TCP #if LWIP_TCP
case NETCONN_TCP: case NETCONN_TCP:
msg->conn->pcb.tcp = tcp_new(); msg->conn->pcb.tcp = tcp_new();
if(msg->conn->pcb.tcp == NULL) { if (msg->conn->pcb.tcp == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
sys_mbox_post(msg->conn->mbox, NULL); sys_mbox_post(msg->conn->mbox, NULL);
return; return;
@ -409,7 +409,7 @@ do_connect(struct api_msg_msg *msg)
break; break;
} }
} }
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -437,7 +437,7 @@ static void
do_disconnect(struct api_msg_msg *msg) do_disconnect(struct api_msg_msg *msg)
{ {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -457,8 +457,8 @@ do_disconnect(struct api_msg_msg *msg)
static void static void
do_listen(struct api_msg_msg *msg) do_listen(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -471,12 +471,12 @@ do_listen(struct api_msg_msg *msg)
#if LWIP_TCP #if LWIP_TCP
case NETCONN_TCP: case NETCONN_TCP:
msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp); msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp);
if(msg->conn->pcb.tcp == NULL) { if (msg->conn->pcb.tcp == NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
} else { } else {
if(msg->conn->acceptmbox == SYS_MBOX_NULL) { if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
msg->conn->acceptmbox = sys_mbox_new(); msg->conn->acceptmbox = sys_mbox_new();
if(msg->conn->acceptmbox == SYS_MBOX_NULL) { if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
msg->conn->err = ERR_MEM; msg->conn->err = ERR_MEM;
break; break;
} }
@ -495,8 +495,8 @@ do_listen(struct api_msg_msg *msg)
static void static void
do_accept(struct api_msg_msg *msg) do_accept(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -515,8 +515,8 @@ do_accept(struct api_msg_msg *msg)
static void static void
do_send(struct api_msg_msg *msg) do_send(struct api_msg_msg *msg)
{ {
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -537,8 +537,8 @@ static void
do_recv(struct api_msg_msg *msg) do_recv(struct api_msg_msg *msg)
{ {
#if LWIP_TCP #if LWIP_TCP
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
if(msg->conn->type == NETCONN_TCP) { if (msg->conn->type == NETCONN_TCP) {
tcp_recved(msg->conn->pcb.tcp, msg->msg.len); tcp_recved(msg->conn->pcb.tcp, msg->msg.len);
} }
} }
@ -552,8 +552,8 @@ do_write(struct api_msg_msg *msg)
#if LWIP_TCP #if LWIP_TCP
err_t err; err_t err;
#endif #endif
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -571,7 +571,7 @@ do_write(struct api_msg_msg *msg)
segments when new outgoing data arrives from the user if any segments when new outgoing data arrives from the user if any
previously transmitted data on the connection remains previously transmitted data on the connection remains
unacknowledged. */ unacknowledged. */
if(err == ERR_OK && msg->conn->pcb.tcp->unacked == NULL) { if (err == ERR_OK && msg->conn->pcb.tcp->unacked == NULL) {
tcp_output(msg->conn->pcb.tcp); tcp_output(msg->conn->pcb.tcp);
} }
msg->conn->err = err; msg->conn->err = err;
@ -596,8 +596,8 @@ do_close(struct api_msg_msg *msg)
err = ERR_OK; err = ERR_OK;
if(msg->conn->pcb.tcp != NULL) { if (msg->conn->pcb.tcp != NULL) {
switch(msg->conn->type) { switch (msg->conn->type) {
#if LWIP_UDP #if LWIP_UDP
case NETCONN_UDPLITE: case NETCONN_UDPLITE:
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -608,7 +608,7 @@ do_close(struct api_msg_msg *msg)
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
#if LWIP_TCP #if LWIP_TCP
case NETCONN_TCP: case NETCONN_TCP:
if(msg->conn->pcb.tcp->state == LISTEN) { if (msg->conn->pcb.tcp->state == LISTEN) {
err = tcp_close(msg->conn->pcb.tcp); err = tcp_close(msg->conn->pcb.tcp);
} }
msg->conn->err = err; msg->conn->err = err;

View File

@ -97,7 +97,7 @@ static int err_to_errno_table[11] = {
#define sock_set_errno(sk, e) do { \ #define sock_set_errno(sk, e) do { \
sk->err = (e); \ sk->err = (e); \
set_errno(sk->err); \ set_errno(sk->err); \
} while(0) } while (0)
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static struct lwip_socket * static struct lwip_socket *
@ -105,7 +105,7 @@ get_socket(int s)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
if((s < 0) || (s > NUM_SOCKETS)) { if ((s < 0) || (s > NUM_SOCKETS)) {
DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s)); DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s));
set_errno(EBADF); set_errno(EBADF);
return NULL; return NULL;
@ -113,7 +113,7 @@ get_socket(int s)
sock = &sockets[s]; sock = &sockets[s];
if(!sock->conn) { if (!sock->conn) {
DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s)); DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s));
set_errno(EBADF); set_errno(EBADF);
return NULL; return NULL;
@ -135,7 +135,7 @@ alloc_socket(struct netconn *newconn)
/* allocate a new socket identifier */ /* allocate a new socket identifier */
for(i = 0; i < NUM_SOCKETS; ++i) { for(i = 0; i < NUM_SOCKETS; ++i) {
if(!sockets[i].conn) { if (!sockets[i].conn) {
sockets[i].conn = newconn; sockets[i].conn = newconn;
sockets[i].lastdata = NULL; sockets[i].lastdata = NULL;
sockets[i].lastoffset = 0; sockets[i].lastoffset = 0;
@ -163,7 +163,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s)); DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s));
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -178,13 +178,13 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
sin.sin_port = htons(port); sin.sin_port = htons(port);
sin.sin_addr.s_addr = naddr.addr; sin.sin_addr.s_addr = naddr.addr;
if(*addrlen > sizeof(sin)) if (*addrlen > sizeof(sin))
*addrlen = sizeof(sin); *addrlen = sizeof(sin);
memcpy(addr, &sin, *addrlen); memcpy(addr, &sin, *addrlen);
newsock = alloc_socket(newconn); newsock = alloc_socket(newconn);
if(newsock == -1) { if (newsock == -1) {
netconn_delete(newconn); netconn_delete(newconn);
sock_set_errno(sock, ENOBUFS); sock_set_errno(sock, ENOBUFS);
return -1; return -1;
@ -216,7 +216,7 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
err_t err; err_t err;
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -231,7 +231,7 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
err = netconn_bind(sock->conn, &local_addr, ntohs(local_port)); err = netconn_bind(sock->conn, &local_addr, ntohs(local_port));
if(err != ERR_OK) { if (err != ERR_OK) {
DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err)); DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err));
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return -1; return -1;
@ -255,13 +255,13 @@ lwip_close(int s)
sys_sem_wait(socksem); sys_sem_wait(socksem);
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
sys_sem_signal(socksem); sys_sem_signal(socksem);
return -1; return -1;
} }
netconn_delete(sock->conn); netconn_delete(sock->conn);
if(sock->lastdata) { if (sock->lastdata) {
netbuf_delete(sock->lastdata); netbuf_delete(sock->lastdata);
} }
sock->lastdata = NULL; sock->lastdata = NULL;
@ -279,7 +279,7 @@ lwip_connect(int s, struct sockaddr *name, socklen_t namelen)
err_t err; err_t err;
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -302,7 +302,7 @@ lwip_connect(int s, struct sockaddr *name, socklen_t namelen)
err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port)); err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
} }
if(err != ERR_OK) { if (err != ERR_OK) {
DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err)); DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return -1; return -1;
@ -321,13 +321,13 @@ lwip_listen(int s, int backlog)
DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog)); DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog));
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
err = netconn_listen(sock->conn); err = netconn_listen(sock->conn);
if(err != ERR_OK) { if (err != ERR_OK) {
DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err)); DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return -1; return -1;
@ -350,12 +350,12 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags)); DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags));
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
/* Check if there is data left from the last recv operation. */ /* Check if there is data left from the last recv operation. */
if(sock->lastdata) { if (sock->lastdata) {
buf = sock->lastdata; buf = sock->lastdata;
} else { } else {
/* If this is non-blocking call, then check first */ /* If this is non-blocking call, then check first */
@ -371,7 +371,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
some from the network. */ some from the network. */
buf = netconn_recv(sock->conn); buf = netconn_recv(sock->conn);
if(!buf) { if (!buf) {
/* We should really do some error checking here. */ /* We should really do some error checking here. */
DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s)); DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
sock_set_errno(sock, 0); sock_set_errno(sock, 0);
@ -383,7 +383,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
buflen -= sock->lastoffset; buflen -= sock->lastoffset;
if(len > buflen) { if (len > buflen) {
copylen = buflen; copylen = buflen;
} else { } else {
copylen = len; copylen = len;
@ -394,7 +394,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
netbuf_copy_partial(buf, mem, copylen, sock->lastoffset); netbuf_copy_partial(buf, mem, copylen, sock->lastoffset);
/* Check to see from where the data was. */ /* Check to see from where the data was. */
if(from && fromlen) { if (from && fromlen) {
struct sockaddr_in sin; struct sockaddr_in sin;
addr = netbuf_fromaddr(buf); addr = netbuf_fromaddr(buf);
@ -406,7 +406,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
sin.sin_port = htons(port); sin.sin_port = htons(port);
sin.sin_addr.s_addr = addr->addr; sin.sin_addr.s_addr = addr->addr;
if(*fromlen > sizeof(sin)) if (*fromlen > sizeof(sin))
*fromlen = sizeof(sin); *fromlen = sizeof(sin);
memcpy(from, &sin, *fromlen); memcpy(from, &sin, *fromlen);
@ -431,7 +431,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
/* If this is a TCP socket, check if there is data left in the /* If this is a TCP socket, check if there is data left in the
buffer. If so, it should be saved in the sock structure for next buffer. If so, it should be saved in the sock structure for next
time around. */ time around. */
if(netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) { if (netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) {
sock->lastdata = buf; sock->lastdata = buf;
sock->lastoffset += copylen; sock->lastoffset += copylen;
} else { } else {
@ -467,16 +467,16 @@ lwip_send(int s, void *data, int size, unsigned int flags)
DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags)); DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags));
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
switch(netconn_type(sock->conn)) { switch (netconn_type(sock->conn)) {
case NETCONN_UDP: case NETCONN_UDP:
/* create a buffer */ /* create a buffer */
buf = netbuf_new(); buf = netbuf_new();
if(!buf) { if (!buf) {
DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ENOBUFS\n", s)); DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ENOBUFS\n", s));
sock_set_errno(sock, ENOBUFS); sock_set_errno(sock, ENOBUFS);
return -1; return -1;
@ -499,7 +499,7 @@ lwip_send(int s, void *data, int size, unsigned int flags)
err = ERR_ARG; err = ERR_ARG;
break; break;
} }
if(err != ERR_OK) { if (err != ERR_OK) {
DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d\n", s, err)); DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d\n", s, err));
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return -1; return -1;
@ -520,7 +520,7 @@ lwip_sendto(int s, void *data, int size, unsigned int flags,
int ret,connected; int ret,connected;
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -542,7 +542,7 @@ lwip_sendto(int s, void *data, int size, unsigned int flags,
/* reset the remote address and port number /* reset the remote address and port number
of the connection */ of the connection */
if(connected) if (connected)
netconn_connect(sock->conn, &addr, port); netconn_connect(sock->conn, &addr, port);
else else
netconn_disconnect(sock->conn); netconn_disconnect(sock->conn);
@ -556,7 +556,7 @@ lwip_socket(int domain, int type, int protocol)
int i; int i;
/* create a netconn */ /* create a netconn */
switch(type) { switch (type) {
case SOCK_DGRAM: case SOCK_DGRAM:
conn = netconn_new_with_callback(NETCONN_UDP, event_callback); conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
@ -571,7 +571,7 @@ lwip_socket(int domain, int type, int protocol)
return -1; return -1;
} }
if(!conn) { if (!conn) {
DEBUGF(SOCKETS_DEBUG, ("-1 / ENOBUFS (could not create netconn)\n")); DEBUGF(SOCKETS_DEBUG, ("-1 / ENOBUFS (could not create netconn)\n"));
set_errno(ENOBUFS); set_errno(ENOBUFS);
return -1; return -1;
@ -579,7 +579,7 @@ lwip_socket(int domain, int type, int protocol)
i = alloc_socket(conn); i = alloc_socket(conn);
if(i == -1) { if (i == -1) {
netconn_delete(conn); netconn_delete(conn);
set_errno(ENOBUFS); set_errno(ENOBUFS);
return -1; return -1;
@ -612,7 +612,7 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
currently match */ currently match */
for(i = 0; i < maxfdp1; i++) for(i = 0; i < maxfdp1; i++)
{ {
if(FD_ISSET(i, readset)) if (FD_ISSET(i, readset))
{ {
/* See if netconn of this socket is ready for read */ /* See if netconn of this socket is ready for read */
p_sock = get_socket(i); p_sock = get_socket(i);
@ -623,7 +623,7 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
nready++; nready++;
} }
} }
if(FD_ISSET(i, writeset)) if (FD_ISSET(i, writeset))
{ {
/* See if netconn of this socket is ready for write */ /* See if netconn of this socket is ready for write */
p_sock = get_socket(i); p_sock = get_socket(i);
@ -888,7 +888,7 @@ int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
struct ip_addr naddr; struct ip_addr naddr;
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -908,7 +908,7 @@ int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
sin.sin_port = htons(sin.sin_port); sin.sin_port = htons(sin.sin_port);
sin.sin_addr.s_addr = naddr.addr; sin.sin_addr.s_addr = naddr.addr;
if(*namelen > sizeof(sin)) if (*namelen > sizeof(sin))
*namelen = sizeof(sin); *namelen = sizeof(sin);
memcpy(name, &sin, *namelen); memcpy(name, &sin, *namelen);
@ -923,7 +923,7 @@ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
struct ip_addr *naddr; struct ip_addr *naddr;
sock = get_socket(s); sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
@ -943,7 +943,7 @@ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
sin.sin_port = htons(sin.sin_port); sin.sin_port = htons(sin.sin_port);
sin.sin_addr.s_addr = naddr->addr; sin.sin_addr.s_addr = naddr->addr;
if(*namelen > sizeof(sin)) if (*namelen > sizeof(sin))
*namelen = sizeof(sin); *namelen = sizeof(sin);
memcpy(name, &sin, *namelen); memcpy(name, &sin, *namelen);
@ -956,14 +956,14 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
int err = ENOSYS; int err = ENOSYS;
struct lwip_socket *sock = get_socket(s); struct lwip_socket *sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
if(level == SOL_SOCKET) { if (level == SOL_SOCKET) {
switch(optname) { switch (optname) {
case SO_ERROR: case SO_ERROR:
if(!optval || !optlen || (*optlen != sizeof(int))) { if (!optval || !optlen || (*optlen != sizeof(int))) {
err = EINVAL; err = EINVAL;
break; break;
} }
@ -988,12 +988,12 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
struct lwip_socket *sock = get_socket(s); struct lwip_socket *sock = get_socket(s);
int err = ENOSYS; int err = ENOSYS;
if(!sock) { if (!sock) {
return -1; return -1;
} }
if(level == SOL_SOCKET) { if (level == SOL_SOCKET) {
switch(optname) { switch (optname) {
case SO_REUSEADDR: case SO_REUSEADDR:
DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, ..)\n", s)); DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, ..)\n", s));
/* XXX just pretend we support this for now */ /* XXX just pretend we support this for now */
@ -1015,13 +1015,13 @@ int lwip_ioctl(int s, long cmd, void *argp)
{ {
struct lwip_socket *sock = get_socket(s); struct lwip_socket *sock = get_socket(s);
if(!sock) { if (!sock) {
return -1; return -1;
} }
switch(cmd) { switch (cmd) {
case FIONREAD: case FIONREAD:
if(!argp) { if (!argp) {
sock_set_errno(sock, EINVAL); sock_set_errno(sock, EINVAL);
return -1; return -1;
} }
@ -1033,7 +1033,7 @@ int lwip_ioctl(int s, long cmd, void *argp)
return 0; return 0;
case FIONBIO: case FIONBIO:
if(argp && *(u32_t*)argp) if (argp && *(u32_t*)argp)
sock->flags |= O_NONBLOCK; sock->flags |= O_NONBLOCK;
else else
sock->flags &= ~O_NONBLOCK; sock->flags &= ~O_NONBLOCK;

View File

@ -57,7 +57,7 @@ tcpip_tcp_timer(void *arg)
(void)arg; (void)arg;
tcp_tmr(); tcp_tmr();
if(tcp_active_pcbs || tcp_tw_pcbs) { if (tcp_active_pcbs || tcp_tw_pcbs) {
sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL); sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
} else { } else {
tcpip_tcp_timer_active = 0; tcpip_tcp_timer_active = 0;
@ -67,7 +67,7 @@ tcpip_tcp_timer(void *arg)
void void
tcp_timer_needed(void) tcp_timer_needed(void)
{ {
if(!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) { if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
tcpip_tcp_timer_active = 1; tcpip_tcp_timer_active = 1;
sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL); sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
} }
@ -88,13 +88,13 @@ tcpip_thread(void *arg)
#if LWIP_TCP #if LWIP_TCP
tcp_init(); tcp_init();
#endif #endif
if(tcpip_init_done != NULL) { if (tcpip_init_done != NULL) {
tcpip_init_done(tcpip_init_done_arg); tcpip_init_done(tcpip_init_done_arg);
} }
while(1) { /* MAIN Loop */ while (1) { /* MAIN Loop */
sys_mbox_fetch(mbox, (void *)&msg); sys_mbox_fetch(mbox, (void *)&msg);
switch(msg->type) { switch (msg->type) {
case TCPIP_MSG_API: case TCPIP_MSG_API:
DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg)); DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
api_msg_input(msg->msg.apimsg); api_msg_input(msg->msg.apimsg);
@ -120,7 +120,7 @@ tcpip_input(struct pbuf *p, struct netif *inp)
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_mallocp(MEMP_TCPIP_MSG);
if(msg == NULL) { if (msg == NULL) {
pbuf_free(p); pbuf_free(p);
return ERR_MEM; return ERR_MEM;
} }
@ -138,7 +138,7 @@ tcpip_callback(void (*f)(void *ctx), void *ctx)
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_mallocp(MEMP_TCPIP_MSG);
if(msg == NULL) { if (msg == NULL) {
return ERR_MEM; return ERR_MEM;
} }
@ -154,7 +154,7 @@ tcpip_apimsg(struct api_msg *apimsg)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_mallocp(MEMP_TCPIP_MSG);
if(msg == NULL) { if (msg == NULL) {
memp_free(MEMP_API_MSG, apimsg); memp_free(MEMP_API_MSG, apimsg);
return; return;
} }

View File

@ -61,7 +61,7 @@ lwip_chksum(void *dataptr, int len)
} }
/* add up any odd byte */ /* add up any odd byte */
if(len == 1) { if (len == 1) {
acc += htons((u16_t)((*(u8_t *)dataptr) & 0xff) << 8); acc += htons((u16_t)((*(u8_t *)dataptr) & 0xff) << 8);
DEBUGF(INET_DEBUG, ("inet: chksum: odd byte %d\n", *(u8_t *)dataptr)); DEBUGF(INET_DEBUG, ("inet: chksum: odd byte %d\n", *(u8_t *)dataptr));
} else { } else {
@ -69,7 +69,7 @@ lwip_chksum(void *dataptr, int len)
} }
acc = (acc >> 16) + (acc & 0xffffUL); acc = (acc >> 16) + (acc & 0xffffUL);
if((acc & 0xffff0000) != 0) { if ((acc & 0xffff0000) != 0) {
acc = (acc >> 16) + (acc & 0xffffUL); acc = (acc >> 16) + (acc & 0xffffUL);
} }
@ -97,17 +97,17 @@ inet_chksum_pseudo(struct pbuf *p,
DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", (void *) q, (void *)q->next)); DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", (void *) q, (void *)q->next));
acc += lwip_chksum(q->payload, q->len); acc += lwip_chksum(q->payload, q->len);
/*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/ /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffffUL) + (acc >> 16); acc = (acc & 0xffffUL) + (acc >> 16);
} }
if(q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
} }
/*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%lx \n", acc));*/ /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%lx \n", acc));*/
} }
if(swapped) { if (swapped) {
acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
} }
acc += (src->addr & 0xffffUL); acc += (src->addr & 0xffffUL);
@ -117,7 +117,7 @@ inet_chksum_pseudo(struct pbuf *p,
acc += (u32_t)htons((u16_t)proto); acc += (u32_t)htons((u16_t)proto);
acc += (u32_t)htons(proto_len); acc += (u32_t)htons(proto_len);
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffffUL) + (acc >> 16); acc = (acc & 0xffffUL) + (acc >> 16);
} }
DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc)); DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc));
@ -136,7 +136,7 @@ inet_chksum(void *dataptr, u16_t len)
u32_t acc; u32_t acc;
acc = lwip_chksum(dataptr, len); acc = lwip_chksum(dataptr, len);
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
return ~(acc & 0xffff); return ~(acc & 0xffff);
@ -153,16 +153,16 @@ inet_chksum_pbuf(struct pbuf *p)
swapped = 0; swapped = 0;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
acc += lwip_chksum(q->payload, q->len); acc += lwip_chksum(q->payload, q->len);
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffffUL) + (acc >> 16); acc = (acc & 0xffffUL) + (acc >> 16);
} }
if(q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8); acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
} }
} }
if(swapped) { if (swapped) {
acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8); acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
} }
return ~(acc & 0xffffUL); return ~(acc & 0xffffUL);

View File

@ -67,7 +67,7 @@ chksum(void *dataptr, u16_t len)
} }
/* add up any odd byte */ /* add up any odd byte */
if(len == 1) { if (len == 1) {
acc += htons((u16_t)(*(u8_t *)dataptr) << 8); acc += htons((u16_t)(*(u8_t *)dataptr) << 8);
} }
@ -93,23 +93,23 @@ inet_chksum_pseudo(struct pbuf *p,
swapped = 0; swapped = 0;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
acc += chksum(q->payload, q->len); acc += chksum(q->payload, q->len);
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
if(q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
} }
if(swapped) { if (swapped) {
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
for(i = 0; i < 8; i++) { for(i = 0; i < 8; i++) {
acc += ((u16_t *)src->addr)[i] & 0xffff; acc += ((u16_t *)src->addr)[i] & 0xffff;
acc += ((u16_t *)dest->addr)[i] & 0xffff; acc += ((u16_t *)dest->addr)[i] & 0xffff;
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
} }
@ -117,7 +117,7 @@ inet_chksum_pseudo(struct pbuf *p,
acc += ((u16_t *)&proto_len)[0] & 0xffff; acc += ((u16_t *)&proto_len)[0] & 0xffff;
acc += ((u16_t *)&proto_len)[1] & 0xffff; acc += ((u16_t *)&proto_len)[1] & 0xffff;
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
return ~(acc & 0xffff); return ~(acc & 0xffff);
@ -151,16 +151,16 @@ inet_chksum_pbuf(struct pbuf *p)
swapped = 0; swapped = 0;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
acc += chksum(q->payload, q->len); acc += chksum(q->payload, q->len);
while(acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
if(q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = (acc & 0xff << 8) | (acc & 0xff00 >> 8); acc = (acc & 0xff << 8) | (acc & 0xff00 >> 8);
} }
} }
if(swapped) { if (swapped) {
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
return ~(acc & 0xffff); return ~(acc & 0xffff);

View File

@ -74,9 +74,9 @@ icmp_input(struct pbuf *p, struct netif *inp)
type = *((u8_t *)p->payload); type = *((u8_t *)p->payload);
code = *(((u8_t *)p->payload)+1); code = *(((u8_t *)p->payload)+1);
switch(type) { switch (type) {
case ICMP_ECHO: case ICMP_ECHO:
if(ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) || if (ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) ||
ip_addr_ismulticast(&iphdr->dest)) { ip_addr_ismulticast(&iphdr->dest)) {
DEBUGF(ICMP_DEBUG, ("Smurf.\n")); DEBUGF(ICMP_DEBUG, ("Smurf.\n"));
#ifdef ICMP_STATS #ifdef ICMP_STATS
@ -87,7 +87,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
} }
DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n"));
DEBUGF(DEMO_DEBUG, ("Pong!\n")); DEBUGF(DEMO_DEBUG, ("Pong!\n"));
if(p->tot_len < sizeof(struct icmp_echo_hdr)) { if (p->tot_len < sizeof(struct icmp_echo_hdr)) {
DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n"));
pbuf_free(p); pbuf_free(p);
#ifdef ICMP_STATS #ifdef ICMP_STATS
@ -98,7 +98,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
return; return;
} }
iecho = p->payload; iecho = p->payload;
if(inet_chksum_pbuf(p) != 0) { if (inet_chksum_pbuf(p) != 0) {
DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n"));
pbuf_free(p); pbuf_free(p);
#ifdef ICMP_STATS #ifdef ICMP_STATS
@ -112,7 +112,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
iphdr->dest.addr = tmpaddr.addr; iphdr->dest.addr = tmpaddr.addr;
ICMPH_TYPE_SET(iecho, ICMP_ER); ICMPH_TYPE_SET(iecho, ICMP_ER);
/* adjust the checksum */ /* adjust the checksum */
if(iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) { if (iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) {
iecho->chksum += htons(ICMP_ECHO << 8) + 1; iecho->chksum += htons(ICMP_ECHO << 8) + 1;
} else { } else {
iecho->chksum += htons(ICMP_ECHO << 8); iecho->chksum += htons(ICMP_ECHO << 8);
@ -126,7 +126,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
snmp_inc_icmpoutechoreps(); snmp_inc_icmpoutechoreps();
pbuf_header(p, hlen); pbuf_header(p, hlen);
ip_output_if(p, &(iphdr->src), IP_HDRINCL, ip_output_if (p, &(iphdr->src), IP_HDRINCL,
IPH_TTL(iphdr), IP_PROTO_ICMP, inp); IPH_TTL(iphdr), IP_PROTO_ICMP, inp);
break; break;
default: default:

View File

@ -87,25 +87,25 @@ ip_lookup(void *header, struct netif *inp)
iphdr = header; iphdr = header;
/* not IP v4? */ /* not IP v4? */
if(IPH_V(iphdr) != 4) { if (IPH_V(iphdr) != 4) {
return 0; return 0;
} }
/* Immediately accept/decline packets that are fragments or has /* Immediately accept/decline packets that are fragments or has
options. */ options. */
#if IP_REASSEMBLY == 0 #if IP_REASSEMBLY == 0
/* if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { /* if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
return 0; return 0;
}*/ }*/
#endif /* IP_REASSEMBLY == 0 */ #endif /* IP_REASSEMBLY == 0 */
#if IP_OPTIONS == 0 #if IP_OPTIONS == 0
if(IPH_HL(iphdr) != 5) { if (IPH_HL(iphdr) != 5) {
return 0; return 0;
} }
#endif /* IP_OPTIONS == 0 */ #endif /* IP_OPTIONS == 0 */
switch(IPH_PROTO(iphdr)) { switch (IPH_PROTO(iphdr)) {
#if LWIP_UDP > 0 #if LWIP_UDP > 0
case IP_PROTO_UDP: case IP_PROTO_UDP:
return udp_lookup(iphdr, inp); return udp_lookup(iphdr, inp);
@ -138,7 +138,7 @@ ip_route(struct ip_addr *dest)
/* iterate through netifs */ /* iterate through netifs */
for(netif = netif_list; netif != NULL; netif = netif->next) { for(netif = netif_list; netif != NULL; netif = netif->next) {
/* network mask matches? */ /* network mask matches? */
if(ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) { if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
/* return netif on which to forward IP packet */ /* return netif on which to forward IP packet */
return netif; return netif;
} }
@ -163,7 +163,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
PERF_START; PERF_START;
/* Find network interface where to forward this IP packet to. */ /* Find network interface where to forward this IP packet to. */
netif = ip_route((struct ip_addr *)&(iphdr->dest)); netif = ip_route((struct ip_addr *)&(iphdr->dest));
if(netif == NULL) { if (netif == NULL) {
DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n", DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n",
iphdr->dest.addr)); iphdr->dest.addr));
snmp_inc_ipnoroutes(); snmp_inc_ipnoroutes();
@ -171,7 +171,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
} }
/* Do not forward packets onto the same network interface on which /* Do not forward packets onto the same network interface on which
they arrived. */ they arrived. */
if(netif == inp) { if (netif == inp) {
DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n")); DEBUGF(IP_DEBUG, ("ip_forward: not bouncing packets back on incoming interface.\n"));
snmp_inc_ipnoroutes(); snmp_inc_ipnoroutes();
return; return;
@ -180,9 +180,9 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
/* decrement TTL */ /* decrement TTL */
IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1); IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
/* send ICMP if TTL == 0 */ /* send ICMP if TTL == 0 */
if(IPH_TTL(iphdr) == 0) { if (IPH_TTL(iphdr) == 0) {
/* Don't send ICMP messages in response to ICMP messages */ /* Don't send ICMP messages in response to ICMP messages */
if(IPH_PROTO(iphdr) != IP_PROTO_ICMP) { if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
icmp_time_exceeded(p, ICMP_TE_TTL); icmp_time_exceeded(p, ICMP_TE_TTL);
snmp_inc_icmpouttimeexcds(); snmp_inc_icmpouttimeexcds();
} }
@ -190,7 +190,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
} }
/* Incrementally update the IP checksum. */ /* Incrementally update the IP checksum. */
if(IPH_CHKSUM(iphdr) >= htons(0xffff - 0x100)) { if (IPH_CHKSUM(iphdr) >= htons(0xffff - 0x100)) {
IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100) + 1); IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100) + 1);
} else { } else {
IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100)); IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100));
@ -235,7 +235,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
/* identify the IP header */ /* identify the IP header */
iphdr = p->payload; iphdr = p->payload;
if(IPH_V(iphdr) != 4) { if (IPH_V(iphdr) != 4) {
DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr))); DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr)));
#if IP_DEBUG #if IP_DEBUG
ip_debug_print(p); ip_debug_print(p);
@ -254,7 +254,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
iphdrlen *= 4; iphdrlen *= 4;
/* header length exceeds first pbuf length? */ /* header length exceeds first pbuf length? */
if(iphdrlen > p->len) { if (iphdrlen > p->len) {
DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n",
iphdrlen, p->len)); iphdrlen, p->len));
/* free (drop) packet pbufs */ /* free (drop) packet pbufs */
@ -268,7 +268,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
} }
/* verify checksum */ /* verify checksum */
if(inet_chksum(iphdr, iphdrlen) != 0) { if (inet_chksum(iphdr, iphdrlen) != 0) {
DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen)));
#if IP_DEBUG #if IP_DEBUG
@ -297,10 +297,10 @@ ip_input(struct pbuf *p, struct netif *inp) {
iphdr->dest.addr & ~(netif->netmask.addr))); iphdr->dest.addr & ~(netif->netmask.addr)));
/* interface configured? */ /* interface configured? */
if(!ip_addr_isany(&(netif->ip_addr))) if (!ip_addr_isany(&(netif->ip_addr)))
{ {
/* unicast to this interface address? */ /* unicast to this interface address? */
if(ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) || if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
/* or broadcast matching this interface network address? */ /* or broadcast matching this interface network address? */
(ip_addr_isbroadcast(&(iphdr->dest), &(netif->netmask)) && (ip_addr_isbroadcast(&(iphdr->dest), &(netif->netmask)) &&
ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) || ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
@ -317,9 +317,9 @@ ip_input(struct pbuf *p, struct netif *inp) {
/* Pass DHCP messages regardless of destination address. DHCP traffic is addressed /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
using link layer addressing (such as Ethernet MAC) so we must not filter on IP. using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
According to RFC 1542 section 3.1.1, referred by RFC 2131). */ According to RFC 1542 section 3.1.1, referred by RFC 2131). */
if(netif == NULL) { if (netif == NULL) {
/* remote port is DHCP server? */ /* remote port is DHCP server? */
if(IPH_PROTO(iphdr) == IP_PROTO_UDP) { if (IPH_PROTO(iphdr) == IP_PROTO_UDP) {
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n", DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n",
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest))); ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest)));
if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) { if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) {
@ -330,12 +330,12 @@ ip_input(struct pbuf *p, struct netif *inp) {
} }
#endif /* LWIP_DHCP */ #endif /* LWIP_DHCP */
/* packet not for us? */ /* packet not for us? */
if(netif == NULL) { if (netif == NULL) {
/* packet not for us, route or discard */ /* packet not for us, route or discard */
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n")); DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n"));
#if IP_FORWARD #if IP_FORWARD
/* non-broadcast packet? */ /* non-broadcast packet? */
if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) { if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) {
/* try to forward IP packet on (other) interfaces */ /* try to forward IP packet on (other) interfaces */
ip_forward(p, iphdr, inp); ip_forward(p, iphdr, inp);
} }
@ -349,16 +349,16 @@ ip_input(struct pbuf *p, struct netif *inp) {
} }
#if IP_REASSEMBLY #if IP_REASSEMBLY
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8)); DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
p = ip_reass(p); p = ip_reass(p);
if(p == NULL) { if (p == NULL) {
return ERR_OK; return ERR_OK;
} }
iphdr = p->payload; iphdr = p->payload;
} }
#else /* IP_REASSEMBLY */ #else /* IP_REASSEMBLY */
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
pbuf_free(p); pbuf_free(p);
DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n",
ntohs(IPH_OFFSET(iphdr)))); ntohs(IPH_OFFSET(iphdr))));
@ -391,7 +391,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
DEBUGF(IP_DEBUG, ("ip_input: p->len %d p->tot_len %d\n", p->len, p->tot_len)); DEBUGF(IP_DEBUG, ("ip_input: p->len %d p->tot_len %d\n", p->len, p->tot_len));
#endif /* IP_DEBUG */ #endif /* IP_DEBUG */
switch(IPH_PROTO(iphdr)) { switch (IPH_PROTO(iphdr)) {
#if LWIP_UDP > 0 #if LWIP_UDP > 0
case IP_PROTO_UDP: case IP_PROTO_UDP:
snmp_inc_ipindelivers(); snmp_inc_ipindelivers();
@ -410,7 +410,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
break; break;
default: default:
/* send ICMP destination protocol unreachable unless is was a broadcast */ /* send ICMP destination protocol unreachable unless is was a broadcast */
if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) && if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) &&
!ip_addr_ismulticast(&(iphdr->dest))) { !ip_addr_ismulticast(&(iphdr->dest))) {
p->payload = iphdr; p->payload = iphdr;
icmp_dest_unreach(p, ICMP_DUR_PROTO); icmp_dest_unreach(p, ICMP_DUR_PROTO);
@ -439,7 +439,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
*/ */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t err_t
ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t ttl,
u8_t proto, struct netif *netif) u8_t proto, struct netif *netif)
{ {
@ -448,8 +448,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
snmp_inc_ipoutrequests(); snmp_inc_ipoutrequests();
if(dest != IP_HDRINCL) { if (dest != IP_HDRINCL) {
if(pbuf_header(p, IP_HLEN)) { if (pbuf_header(p, IP_HLEN)) {
DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n")); DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n"));
#ifdef IP_STATS #ifdef IP_STATS
@ -472,7 +472,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
IPH_ID_SET(iphdr, htons(ip_id)); IPH_ID_SET(iphdr, htons(ip_id));
++ip_id; ++ip_id;
if(ip_addr_isany(src)) { if (ip_addr_isany(src)) {
ip_addr_set(&(iphdr->src), &(netif->ip_addr)); ip_addr_set(&(iphdr->src), &(netif->ip_addr));
} else { } else {
ip_addr_set(&(iphdr->src), src); ip_addr_set(&(iphdr->src), src);
@ -516,7 +516,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
{ {
struct netif *netif; struct netif *netif;
if((netif = ip_route(dest)) == NULL) { if ((netif = ip_route(dest)) == NULL) {
DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr)); DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr));
#ifdef IP_STATS #ifdef IP_STATS
@ -526,7 +526,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
return ERR_RTE; return ERR_RTE;
} }
return ip_output_if(p, src, dest, ttl, proto, netif); return ip_output_if (p, src, dest, ttl, proto, netif);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
#if IP_DEBUG #if IP_DEBUG

View File

@ -94,10 +94,10 @@ static void
ip_reass_timer(void *arg) ip_reass_timer(void *arg)
{ {
(void)arg; (void)arg;
if(ip_reasstmr > 1) { if (ip_reasstmr > 1) {
ip_reasstmr--; ip_reasstmr--;
sys_timeout(IP_REASS_TMO, ip_reass_timer, NULL); sys_timeout(IP_REASS_TMO, ip_reass_timer, NULL);
} else if(ip_reasstmr == 1) } else if (ip_reasstmr == 1)
ip_reasstmr = 0; ip_reasstmr = 0;
} }

View File

@ -58,11 +58,11 @@ icmp_input(struct pbuf *p, struct netif *inp)
type = ((char *)p->payload)[0]; type = ((char *)p->payload)[0];
switch(type) { switch (type) {
case ICMP6_ECHO: case ICMP6_ECHO:
DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n"));
if(p->tot_len < sizeof(struct icmp_echo_hdr)) { if (p->tot_len < sizeof(struct icmp_echo_hdr)) {
DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n"));
pbuf_free(p); pbuf_free(p);
@ -74,7 +74,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
} }
iecho = p->payload; iecho = p->payload;
iphdr = (struct ip_hdr *)((char *)p->payload - IP_HLEN); iphdr = (struct ip_hdr *)((char *)p->payload - IP_HLEN);
if(inet_chksum_pbuf(p) != 0) { if (inet_chksum_pbuf(p) != 0) {
DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo (%x)\n", inet_chksum_pseudo(p, &(iphdr->src), &(iphdr->dest), IP_PROTO_ICMP, p->tot_len))); DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo (%x)\n", inet_chksum_pseudo(p, &(iphdr->src), &(iphdr->dest), IP_PROTO_ICMP, p->tot_len)));
#ifdef ICMP_STATS #ifdef ICMP_STATS
@ -88,7 +88,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
ip_addr_set(&(iphdr->dest), &tmpaddr); ip_addr_set(&(iphdr->dest), &tmpaddr);
iecho->type = ICMP6_ER; iecho->type = ICMP6_ER;
/* adjust the checksum */ /* adjust the checksum */
if(iecho->chksum >= htons(0xffff - (ICMP6_ECHO << 8))) { if (iecho->chksum >= htons(0xffff - (ICMP6_ECHO << 8))) {
iecho->chksum += htons(ICMP6_ECHO << 8) + 1; iecho->chksum += htons(ICMP6_ECHO << 8) + 1;
} else { } else {
iecho->chksum += htons(ICMP6_ECHO << 8); iecho->chksum += htons(ICMP6_ECHO << 8);
@ -99,7 +99,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
#endif /* ICMP_STATS */ #endif /* ICMP_STATS */
/* DEBUGF("icmp: p->len %d p->tot_len %d\n", p->len, p->tot_len);*/ /* DEBUGF("icmp: p->len %d p->tot_len %d\n", p->len, p->tot_len);*/
ip_output_if(p, &(iphdr->src), IP_HDRINCL, ip_output_if (p, &(iphdr->src), IP_HDRINCL,
iphdr->hoplim, IP_PROTO_ICMP, inp); iphdr->hoplim, IP_PROTO_ICMP, inp);
break; break;
default: default:

View File

@ -77,7 +77,7 @@ ip_route(struct ip_addr *dest)
struct netif *netif; struct netif *netif;
for(netif = netif_list; netif != NULL; netif = netif->next) { for(netif = netif_list; netif != NULL; netif = netif->next) {
if(ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) { if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
return netif; return netif;
} }
} }
@ -99,7 +99,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr)
PERF_START; PERF_START;
if((netif = ip_route((struct ip_addr *)&(iphdr->dest))) == NULL) { if ((netif = ip_route((struct ip_addr *)&(iphdr->dest))) == NULL) {
DEBUGF(IP_DEBUG, ("ip_input: no forwarding route found for ")); DEBUGF(IP_DEBUG, ("ip_input: no forwarding route found for "));
#if IP_DEBUG #if IP_DEBUG
@ -110,9 +110,9 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr)
return; return;
} }
/* Decrement TTL and send ICMP if ttl == 0. */ /* Decrement TTL and send ICMP if ttl == 0. */
if(--iphdr->hoplim == 0) { if (--iphdr->hoplim == 0) {
/* Don't send ICMP messages in response to ICMP messages */ /* Don't send ICMP messages in response to ICMP messages */
if(iphdr->nexthdr != IP_PROTO_ICMP) { if (iphdr->nexthdr != IP_PROTO_ICMP) {
icmp_time_exceeded(p, ICMP_TE_TTL); icmp_time_exceeded(p, ICMP_TE_TTL);
} }
pbuf_free(p); pbuf_free(p);
@ -174,7 +174,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
iphdr = p->payload; iphdr = p->payload;
if(iphdr->v != 6) { if (iphdr->v != 6) {
DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number\n")); DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number\n"));
#if IP_DEBUG #if IP_DEBUG
ip_debug_print(p); ip_debug_print(p);
@ -196,13 +196,13 @@ ip_input(struct pbuf *p, struct netif *inp) {
ip_addr_debug_print(&(netif->ip_addr)); ip_addr_debug_print(&(netif->ip_addr));
DEBUGF(IP_DEBUG, ("\n")); DEBUGF(IP_DEBUG, ("\n"));
#endif /* IP_DEBUG */ #endif /* IP_DEBUG */
if(ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr))) { if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr))) {
break; break;
} }
} }
if(netif == NULL) { if (netif == NULL) {
/* packet not for us, route or discard */ /* packet not for us, route or discard */
#ifdef IP_FORWARD #ifdef IP_FORWARD
ip_forward(p, iphdr); ip_forward(p, iphdr);
@ -223,7 +223,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
pbuf_header(p, -IP_HLEN); pbuf_header(p, -IP_HLEN);
switch(iphdr->nexthdr) { switch (iphdr->nexthdr) {
case IP_PROTO_UDP: case IP_PROTO_UDP:
udp_input(p); udp_input(p);
break; break;
@ -258,7 +258,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
*/ */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t err_t
ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t ttl,
u8_t proto, struct netif *netif) u8_t proto, struct netif *netif)
{ {
@ -267,7 +267,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
PERF_START; PERF_START;
printf("len %u tot_len %u\n", p->len, p->tot_len); printf("len %u tot_len %u\n", p->len, p->tot_len);
if(pbuf_header(p, IP_HLEN)) { if (pbuf_header(p, IP_HLEN)) {
DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n")); DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n"));
#ifdef IP_STATS #ifdef IP_STATS
++lwip_stats.ip.err; ++lwip_stats.ip.err;
@ -280,7 +280,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
iphdr = p->payload; iphdr = p->payload;
if(dest != IP_HDRINCL) { if (dest != IP_HDRINCL) {
printf("!IP_HDRLINCL\n"); printf("!IP_HDRLINCL\n");
iphdr->hoplim = ttl; iphdr->hoplim = ttl;
iphdr->nexthdr = proto; iphdr->nexthdr = proto;
@ -289,7 +289,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
iphdr->v = 6; iphdr->v = 6;
if(ip_addr_isany(src)) { if (ip_addr_isany(src)) {
ip_addr_set(&(iphdr->src), &(netif->ip_addr)); ip_addr_set(&(iphdr->src), &(netif->ip_addr));
} else { } else {
ip_addr_set(&(iphdr->src), src); ip_addr_set(&(iphdr->src), src);
@ -323,7 +323,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t proto) u8_t ttl, u8_t proto)
{ {
struct netif *netif; struct netif *netif;
if((netif = ip_route(dest)) == NULL) { if ((netif = ip_route(dest)) == NULL) {
DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%lx\n", dest->addr)); DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%lx\n", dest->addr));
#ifdef IP_STATS #ifdef IP_STATS
++lwip_stats.ip.rterr; ++lwip_stats.ip.rterr;
@ -331,7 +331,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
return ERR_RTE; return ERR_RTE;
} }
return ip_output_if(p, src, dest, ttl, proto, netif); return ip_output_if (p, src, dest, ttl, proto, netif);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
#if IP_DEBUG #if IP_DEBUG

View File

@ -67,7 +67,7 @@ ip_addr_set(struct ip_addr *dest, struct ip_addr *src)
int int
ip_addr_isany(struct ip_addr *addr) ip_addr_isany(struct ip_addr *addr)
{ {
if(addr == NULL) return 1; if (addr == NULL) return 1;
return((addr->addr[0] | addr->addr[1] | addr->addr[2] | addr->addr[3]) == 0); return((addr->addr[0] | addr->addr[1] | addr->addr[2] | addr->addr[3]) == 0);
} }

View File

@ -87,8 +87,8 @@ plug_holes(struct mem *mem)
LWIP_ASSERT("plug_holes: mem->next <= MEM_SIZE", mem->next <= MEM_SIZE); LWIP_ASSERT("plug_holes: mem->next <= MEM_SIZE", mem->next <= MEM_SIZE);
nmem = (struct mem *)&ram[mem->next]; nmem = (struct mem *)&ram[mem->next];
if(mem != nmem && nmem->used == 0 && (u8_t *)nmem != (u8_t *)ram_end) { if (mem != nmem && nmem->used == 0 && (u8_t *)nmem != (u8_t *)ram_end) {
if(lfree == nmem) { if (lfree == nmem) {
lfree = mem; lfree = mem;
} }
mem->next = nmem->next; mem->next = nmem->next;
@ -97,8 +97,8 @@ plug_holes(struct mem *mem)
/* plug hole backward */ /* plug hole backward */
pmem = (struct mem *)&ram[mem->prev]; pmem = (struct mem *)&ram[mem->prev];
if(pmem != mem && pmem->used == 0) { if (pmem != mem && pmem->used == 0) {
if(lfree == mem) { if (lfree == mem) {
lfree = pmem; lfree = pmem;
} }
pmem->next = mem->next; pmem->next = mem->next;
@ -224,7 +224,7 @@ mem_realloc(void *rmem, mem_size_t newsize)
mem2->next = mem->next; mem2->next = mem->next;
mem2->prev = ptr; mem2->prev = ptr;
mem->next = ptr2; mem->next = ptr2;
if(mem2->next != MEM_SIZE) { if (mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2; ((struct mem *)&ram[mem2->next])->prev = ptr2;
} }
@ -257,7 +257,7 @@ mem_malloc(mem_size_t size)
for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE; ptr = ((struct mem *)&ram[ptr])->next) { for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE; ptr = ((struct mem *)&ram[ptr])->next) {
mem = (struct mem *)&ram[ptr]; mem = (struct mem *)&ram[ptr];
if(!mem->used && if (!mem->used &&
mem->next - (ptr + SIZEOF_STRUCT_MEM) >= size + SIZEOF_STRUCT_MEM) { mem->next - (ptr + SIZEOF_STRUCT_MEM) >= size + SIZEOF_STRUCT_MEM) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + size; ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
mem2 = (struct mem *)&ram[ptr2]; mem2 = (struct mem *)&ram[ptr2];
@ -273,7 +273,7 @@ mem_malloc(mem_size_t size)
mem->used = 1; mem->used = 1;
#ifdef MEM_STATS #ifdef MEM_STATS
lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM); lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
/* if(lwip_stats.mem.max < lwip_stats.mem.used) { /* if (lwip_stats.mem.max < lwip_stats.mem.used) {
lwip_stats.mem.max = lwip_stats.mem.used; lwip_stats.mem.max = lwip_stats.mem.used;
} */ } */
if (lwip_stats.mem.max < ptr2) { if (lwip_stats.mem.max < ptr2) {
@ -283,7 +283,7 @@ mem_malloc(mem_size_t size)
if (mem == lfree) { if (mem == lfree) {
/* Find next free block after mem */ /* Find next free block after mem */
while(lfree->used && lfree != ram_end) { while (lfree->used && lfree != ram_end) {
lfree = (struct mem *)&ram[lfree->next]; lfree = (struct mem *)&ram[lfree->next];
} }
LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used); LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used);

View File

@ -125,10 +125,10 @@ memp_sanity(void)
for(m = memp_tab[i]; m != NULL; m = m->next) { for(m = memp_tab[i]; m != NULL; m = m->next) {
c = 1; c = 1;
for(n = memp_tab[i]; n != NULL; n = n->next) { for(n = memp_tab[i]; n != NULL; n = n->next) {
if(n == m) { if (n == m) {
--c; --c;
} }
if(c < 0) return 0; /* LW was: abort(); */ if (c < 0) return 0; /* LW was: abort(); */
} }
} }
} }
@ -154,7 +154,7 @@ memp_init(void)
memp = (struct memp *)&memp_memory[0]; memp = (struct memp *)&memp_memory[0];
for(i = 0; i < MEMP_MAX; ++i) { for(i = 0; i < MEMP_MAX; ++i) {
size = MEM_ALIGN_SIZE(memp_sizes[i] + sizeof(struct memp)); size = MEM_ALIGN_SIZE(memp_sizes[i] + sizeof(struct memp));
if(memp_num[i] > 0) { if (memp_num[i] > 0) {
memp_tab[i] = memp; memp_tab[i] = memp;
m = memp; m = memp;
@ -187,12 +187,12 @@ memp_malloc(memp_t type)
memp = memp_tab[type]; memp = memp_tab[type];
if(memp != NULL) { if (memp != NULL) {
memp_tab[type] = memp->next; memp_tab[type] = memp->next;
memp->next = NULL; memp->next = NULL;
#ifdef MEMP_STATS #ifdef MEMP_STATS
++lwip_stats.memp[type].used; ++lwip_stats.memp[type].used;
if(lwip_stats.memp[type].used > lwip_stats.memp[type].max) { if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
lwip_stats.memp[type].max = lwip_stats.memp[type].used; lwip_stats.memp[type].max = lwip_stats.memp[type].used;
} }
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
@ -238,7 +238,7 @@ memp_free(memp_t type, void *mem)
{ {
struct memp *memp; struct memp *memp;
if(mem == NULL) { if (mem == NULL) {
return; return;
} }
memp = (struct memp *)((u8_t *)mem - sizeof(struct memp)); memp = (struct memp *)((u8_t *)mem - sizeof(struct memp));

View File

@ -153,14 +153,14 @@ netif_find(char *name)
struct netif *netif; struct netif *netif;
u8_t num; u8_t num;
if(name == NULL) { if (name == NULL) {
return NULL; return NULL;
} }
num = name[2] - '0'; num = name[2] - '0';
for(netif = netif_list; netif != NULL; netif = netif->next) { for(netif = netif_list; netif != NULL; netif = netif->next) {
if(num == netif->num && if (num == netif->num &&
name[0] == netif->name[0] && name[0] == netif->name[0] &&
name[1] == netif->name[1]) { name[1] == netif->name[1]) {
DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1])); DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));

View File

@ -134,17 +134,17 @@ pbuf_pool_alloc(void)
#if !SYS_LIGHTWEIGHT_PROT #if !SYS_LIGHTWEIGHT_PROT
/* Next, check the actual pbuf pool, but if the pool is locked, we /* Next, check the actual pbuf pool, but if the pool is locked, we
pretend to be out of buffers and return NULL. */ pretend to be out of buffers and return NULL. */
if(pbuf_pool_free_lock) { if (pbuf_pool_free_lock) {
#ifdef PBUF_STATS #ifdef PBUF_STATS
++lwip_stats.pbuf.alloc_locked; ++lwip_stats.pbuf.alloc_locked;
#endif /* PBUF_STATS */ #endif /* PBUF_STATS */
return NULL; return NULL;
} }
pbuf_pool_alloc_lock = 1; pbuf_pool_alloc_lock = 1;
if(!pbuf_pool_free_lock) { if (!pbuf_pool_free_lock) {
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
p = pbuf_pool; p = pbuf_pool;
if(p) { if (p) {
pbuf_pool = p->next; pbuf_pool = p->next;
} }
#if !SYS_LIGHTWEIGHT_PROT #if !SYS_LIGHTWEIGHT_PROT
@ -157,9 +157,9 @@ pbuf_pool_alloc(void)
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
#ifdef PBUF_STATS #ifdef PBUF_STATS
if(p != NULL) { if (p != NULL) {
++lwip_stats.pbuf.used; ++lwip_stats.pbuf.used;
if(lwip_stats.pbuf.used > lwip_stats.pbuf.max) { if (lwip_stats.pbuf.used > lwip_stats.pbuf.max) {
lwip_stats.pbuf.max = lwip_stats.pbuf.used; lwip_stats.pbuf.max = lwip_stats.pbuf.used;
} }
} }
@ -258,7 +258,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
/* remaining length to be allocated */ /* remaining length to be allocated */
rem_len = length - p->len; rem_len = length - p->len;
/* any remaining pbufs to be allocated? */ /* any remaining pbufs to be allocated? */
while(rem_len > 0) { while (rem_len > 0) {
q = pbuf_pool_alloc(); q = pbuf_pool_alloc();
if (q == NULL) { if (q == NULL) {
DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n")); DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n"));
@ -346,13 +346,13 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
SYS_ARCH_PROTECT(old_level); \ SYS_ARCH_PROTECT(old_level); \
PBUF_POOL_FAST_FREE(p); \ PBUF_POOL_FAST_FREE(p); \
SYS_ARCH_UNPROTECT(old_level); \ SYS_ARCH_UNPROTECT(old_level); \
} while(0) } while (0)
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
#define PBUF_POOL_FREE(p) do { \ #define PBUF_POOL_FREE(p) do { \
sys_sem_wait(pbuf_pool_free_sem); \ sys_sem_wait(pbuf_pool_free_sem); \
PBUF_POOL_FAST_FREE(p); \ PBUF_POOL_FAST_FREE(p); \
sys_sem_signal(pbuf_pool_free_sem); \ sys_sem_signal(pbuf_pool_free_sem); \
} while(0) } while (0)
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
/** /**
@ -632,7 +632,7 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
LWIP_ASSERT("h != NULL", h != NULL); LWIP_ASSERT("h != NULL", h != NULL);
LWIP_ASSERT("t != NULL", t != NULL); LWIP_ASSERT("t != NULL", t != NULL);
if(t == NULL) if (t == NULL)
return; return;
/* proceed to last pbuf of chain */ /* proceed to last pbuf of chain */

View File

@ -58,16 +58,16 @@ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
again: again:
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
if(!timeouts || !timeouts->next) { if (!timeouts || !timeouts->next) {
sys_arch_mbox_fetch(mbox, msg, 0); sys_arch_mbox_fetch(mbox, msg, 0);
} else { } else {
if(timeouts->next->time > 0) { if (timeouts->next->time > 0) {
time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time); time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
} else { } else {
time = 0xffffffff; time = 0xffffffff;
} }
if(time == 0xffffffff) { if (time == 0xffffffff) {
/* If time == 0xffffffff, a timeout occured before a message could be /* If time == 0xffffffff, a timeout occured before a message could be
fetched. We should now call the timeout handler and fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */ deallocate the memory allocated for the timeout. */
@ -76,7 +76,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
h = tmptimeout->h; h = tmptimeout->h;
arg = tmptimeout->arg; arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
if(h != NULL) { if (h != NULL) {
DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
h(arg); h(arg);
} }
@ -87,7 +87,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
/* If time != 0xffffffff, a message was received before the timeout /* If time != 0xffffffff, a message was received before the timeout
occured. The time variable is set to the number of occured. The time variable is set to the number of
milliseconds we waited for the message. */ milliseconds we waited for the message. */
if(time <= timeouts->next->time) { if (time <= timeouts->next->time) {
timeouts->next->time -= time; timeouts->next->time -= time;
} else { } else {
timeouts->next->time = 0; timeouts->next->time = 0;
@ -106,23 +106,23 @@ sys_sem_wait(sys_sem_t sem)
sys_timeout_handler h; sys_timeout_handler h;
void *arg; void *arg;
/* while(sys_arch_sem_wait(sem, 1000) == 0); /* while (sys_arch_sem_wait(sem, 1000) == 0);
return;*/ return;*/
again: again:
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
if(!timeouts || !timeouts->next) { if (!timeouts || !timeouts->next) {
sys_arch_sem_wait(sem, 0); sys_arch_sem_wait(sem, 0);
} else { } else {
if(timeouts->next->time > 0) { if (timeouts->next->time > 0) {
time = sys_arch_sem_wait(sem, timeouts->next->time); time = sys_arch_sem_wait(sem, timeouts->next->time);
} else { } else {
time = 0xffffffff; time = 0xffffffff;
} }
if(time == 0xffffffff) { if (time == 0xffffffff) {
/* If time == 0xffffffff, a timeout occured before a message could be /* If time == 0xffffffff, a timeout occured before a message could be
fetched. We should now call the timeout handler and fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */ deallocate the memory allocated for the timeout. */
@ -131,7 +131,7 @@ sys_sem_wait(sys_sem_t sem)
h = tmptimeout->h; h = tmptimeout->h;
arg = tmptimeout->arg; arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
if(h != NULL) { if (h != NULL) {
DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg));
h(arg); h(arg);
} }
@ -143,7 +143,7 @@ sys_sem_wait(sys_sem_t sem)
/* If time != 0xffffffff, a message was received before the timeout /* If time != 0xffffffff, a message was received before the timeout
occured. The time variable is set to the number of occured. The time variable is set to the number of
milliseconds we waited for the message. */ milliseconds we waited for the message. */
if(time <= timeouts->next->time) { if (time <= timeouts->next->time) {
timeouts->next->time -= time; timeouts->next->time -= time;
} else { } else {
timeouts->next->time = 0; timeouts->next->time = 0;
@ -160,7 +160,7 @@ sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
struct sys_timeout *timeout, *t; struct sys_timeout *timeout, *t;
timeout = memp_malloc(MEMP_SYS_TIMEOUT); timeout = memp_malloc(MEMP_SYS_TIMEOUT);
if(timeout == NULL) { if (timeout == NULL) {
return; return;
} }
timeout->next = NULL; timeout->next = NULL;
@ -173,21 +173,21 @@ sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg)); DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg));
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
if(timeouts->next == NULL) { if (timeouts->next == NULL) {
timeouts->next = timeout; timeouts->next = timeout;
return; return;
} }
if(timeouts->next->time > msecs) { if (timeouts->next->time > msecs) {
timeouts->next->time -= msecs; timeouts->next->time -= msecs;
timeout->next = timeouts->next; timeout->next = timeouts->next;
timeouts->next = timeout; timeouts->next = timeout;
} else { } else {
for(t = timeouts->next; t != NULL; t = t->next) { for(t = timeouts->next; t != NULL; t = t->next) {
timeout->time -= t->time; timeout->time -= t->time;
if(t->next == NULL || if (t->next == NULL ||
t->next->time > timeout->time) { t->next->time > timeout->time) {
if(t->next != NULL) { if (t->next != NULL) {
t->next->time -= timeout->time; t->next->time -= timeout->time;
} }
timeout->next = t->next; timeout->next = t->next;

View File

@ -109,16 +109,16 @@ void
tcp_tmr(void) tcp_tmr(void)
{ {
++tcp_timer; ++tcp_timer;
if(tcp_timer == 10) { if (tcp_timer == 10) {
tcp_timer = 0; tcp_timer = 0;
} }
if(tcp_timer & 1) { if (tcp_timer & 1) {
/* Call tcp_fasttmr() every 200 ms, i.e., every other timer /* Call tcp_fasttmr() every 200 ms, i.e., every other timer
tcp_tmr() is called. */ tcp_tmr() is called. */
tcp_fasttmr(); tcp_fasttmr();
} }
if(tcp_timer == 0 || tcp_timer == 5) { if (tcp_timer == 0 || tcp_timer == 5) {
/* Call tcp_slowtmr() every 500 ms, i.e., every fifth timer /* Call tcp_slowtmr() every 500 ms, i.e., every fifth timer
tcp_tmr() is called. */ tcp_tmr() is called. */
tcp_slowtmr(); tcp_slowtmr();
@ -142,7 +142,7 @@ tcp_close(struct tcp_pcb *pcb)
tcp_debug_print_state(pcb->state); tcp_debug_print_state(pcb->state);
DEBUGF(TCP_DEBUG, ("\n")); DEBUGF(TCP_DEBUG, ("\n"));
#endif /* TCP_DEBUG */ #endif /* TCP_DEBUG */
switch(pcb->state) { switch (pcb->state) {
case LISTEN: case LISTEN:
err = ERR_OK; err = ERR_OK;
tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb); tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb);
@ -157,19 +157,19 @@ tcp_close(struct tcp_pcb *pcb)
break; break;
case SYN_RCVD: case SYN_RCVD:
err = tcp_send_ctrl(pcb, TCP_FIN); err = tcp_send_ctrl(pcb, TCP_FIN);
if(err == ERR_OK) { if (err == ERR_OK) {
pcb->state = FIN_WAIT_1; pcb->state = FIN_WAIT_1;
} }
break; break;
case ESTABLISHED: case ESTABLISHED:
err = tcp_send_ctrl(pcb, TCP_FIN); err = tcp_send_ctrl(pcb, TCP_FIN);
if(err == ERR_OK) { if (err == ERR_OK) {
pcb->state = FIN_WAIT_1; pcb->state = FIN_WAIT_1;
} }
break; break;
case CLOSE_WAIT: case CLOSE_WAIT:
err = tcp_send_ctrl(pcb, TCP_FIN); err = tcp_send_ctrl(pcb, TCP_FIN);
if(err == ERR_OK) { if (err == ERR_OK) {
pcb->state = LAST_ACK; pcb->state = LAST_ACK;
} }
break; break;
@ -180,7 +180,7 @@ tcp_close(struct tcp_pcb *pcb)
break; break;
} }
if(pcb != NULL && err == ERR_OK) { if (pcb != NULL && err == ERR_OK) {
err = tcp_output(pcb); err = tcp_output(pcb);
} }
return err; return err;
@ -210,7 +210,7 @@ tcp_abort(struct tcp_pcb *pcb)
/* Figure out on which TCP PCB list we are, and remove us. If we /* Figure out on which TCP PCB list we are, and remove us. If we
are in an active state, call the receive function associated with are in an active state, call the receive function associated with
the PCB with a NULL argument, and send an RST to the remote end. */ the PCB with a NULL argument, and send an RST to the remote end. */
if(pcb->state == TIME_WAIT) { if (pcb->state == TIME_WAIT) {
tcp_pcb_remove(&tcp_tw_pcbs, pcb); tcp_pcb_remove(&tcp_tw_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb); memp_free(MEMP_TCP_PCB, pcb);
} else { } else {
@ -225,14 +225,14 @@ tcp_abort(struct tcp_pcb *pcb)
#endif /* LWIP_CALLBACK_API */ #endif /* LWIP_CALLBACK_API */
errf_arg = pcb->callback_arg; errf_arg = pcb->callback_arg;
tcp_pcb_remove(&tcp_active_pcbs, pcb); tcp_pcb_remove(&tcp_active_pcbs, pcb);
if(pcb->unacked != NULL) { if (pcb->unacked != NULL) {
tcp_segs_free(pcb->unacked); tcp_segs_free(pcb->unacked);
} }
if(pcb->unsent != NULL) { if (pcb->unsent != NULL) {
tcp_segs_free(pcb->unsent); tcp_segs_free(pcb->unsent);
} }
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
if(pcb->ooseq != NULL) { if (pcb->ooseq != NULL) {
tcp_segs_free(pcb->ooseq); tcp_segs_free(pcb->ooseq);
} }
#endif /* TCP_QUEUE_OOSEQ */ #endif /* TCP_QUEUE_OOSEQ */
@ -257,15 +257,15 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{ {
struct tcp_pcb *cpcb; struct tcp_pcb *cpcb;
if(port == 0) { if (port == 0) {
port = tcp_new_port(); port = tcp_new_port();
} }
/* Check if the address already is in use. */ /* Check if the address already is in use. */
for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs; for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs;
cpcb != NULL; cpcb = cpcb->next) { cpcb != NULL; cpcb = cpcb->next) {
if(cpcb->local_port == port) { if (cpcb->local_port == port) {
if(ip_addr_isany(&(cpcb->local_ip)) || if (ip_addr_isany(&(cpcb->local_ip)) ||
ip_addr_isany(ipaddr) || ip_addr_isany(ipaddr) ||
ip_addr_cmp(&(cpcb->local_ip), ipaddr)) { ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
return ERR_USE; return ERR_USE;
@ -274,15 +274,15 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
} }
for(cpcb = tcp_active_pcbs; for(cpcb = tcp_active_pcbs;
cpcb != NULL; cpcb = cpcb->next) { cpcb != NULL; cpcb = cpcb->next) {
if(cpcb->local_port == port) { if (cpcb->local_port == port) {
if(ip_addr_isany(&(cpcb->local_ip)) || if (ip_addr_isany(&(cpcb->local_ip)) ||
ip_addr_isany(ipaddr) || ip_addr_isany(ipaddr) ||
ip_addr_cmp(&(cpcb->local_ip), ipaddr)) { ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
return ERR_USE; return ERR_USE;
} }
} }
} }
if(!ip_addr_isany(ipaddr)) { if (!ip_addr_isany(ipaddr)) {
pcb->local_ip = *ipaddr; pcb->local_ip = *ipaddr;
} }
pcb->local_port = port; pcb->local_port = port;
@ -314,11 +314,11 @@ tcp_listen(struct tcp_pcb *pcb)
struct tcp_pcb_listen *lpcb; struct tcp_pcb_listen *lpcb;
/* already listening? */ /* already listening? */
if(pcb->state == LISTEN) { if (pcb->state == LISTEN) {
return pcb; return pcb;
} }
lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN); lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);
if(lpcb == NULL) { if (lpcb == NULL) {
return NULL; return NULL;
} }
lpcb->callback_arg = pcb->callback_arg; lpcb->callback_arg = pcb->callback_arg;
@ -346,10 +346,10 @@ void
tcp_recved(struct tcp_pcb *pcb, u16_t len) tcp_recved(struct tcp_pcb *pcb, u16_t len)
{ {
pcb->rcv_wnd += len; pcb->rcv_wnd += len;
if(pcb->rcv_wnd > TCP_WND) { if (pcb->rcv_wnd > TCP_WND) {
pcb->rcv_wnd = TCP_WND; pcb->rcv_wnd = TCP_WND;
} }
if(!(pcb->flags & TF_ACK_DELAY) && if (!(pcb->flags & TF_ACK_DELAY) &&
!(pcb->flags & TF_ACK_NOW)) { !(pcb->flags & TF_ACK_NOW)) {
tcp_ack(pcb); tcp_ack(pcb);
} }
@ -375,22 +375,22 @@ tcp_new_port(void)
static u16_t port = TCP_LOCAL_PORT_RANGE_START; static u16_t port = TCP_LOCAL_PORT_RANGE_START;
again: again:
if(++port > TCP_LOCAL_PORT_RANGE_END) { if (++port > TCP_LOCAL_PORT_RANGE_END) {
port = TCP_LOCAL_PORT_RANGE_START; port = TCP_LOCAL_PORT_RANGE_START;
} }
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->local_port == port) { if (pcb->local_port == port) {
goto again; goto again;
} }
} }
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->local_port == port) { if (pcb->local_port == port) {
goto again; goto again;
} }
} }
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->local_port == port) { if (pcb->local_port == port) {
goto again; goto again;
} }
} }
@ -414,13 +414,13 @@ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
u32_t iss; u32_t iss;
DEBUGF(TCP_DEBUG, ("tcp_connect to port %u\n", port)); DEBUGF(TCP_DEBUG, ("tcp_connect to port %u\n", port));
if(ipaddr != NULL) { if (ipaddr != NULL) {
pcb->remote_ip = *ipaddr; pcb->remote_ip = *ipaddr;
} else { } else {
return ERR_VAL; return ERR_VAL;
} }
pcb->remote_port = port; pcb->remote_port = port;
if(pcb->local_port == 0) { if (pcb->local_port == 0) {
pcb->local_port = tcp_new_port(); pcb->local_port = tcp_new_port();
} }
iss = tcp_next_iss(); iss = tcp_next_iss();
@ -446,7 +446,7 @@ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
(pcb->mss & 255)); (pcb->mss & 255));
ret = tcp_enqueue(pcb, NULL, 0, TCP_SYN, 0, (u8_t *)&optdata, 4); ret = tcp_enqueue(pcb, NULL, 0, TCP_SYN, 0, (u8_t *)&optdata, 4);
if(ret == ERR_OK) { if (ret == ERR_OK) {
tcp_output(pcb); tcp_output(pcb);
} }
return ret; return ret;
@ -508,7 +508,7 @@ tcp_slowtmr(void)
/* Reduce congestion window and ssthresh. */ /* Reduce congestion window and ssthresh. */
eff_wnd = MIN(pcb->cwnd, pcb->snd_wnd); eff_wnd = MIN(pcb->cwnd, pcb->snd_wnd);
pcb->ssthresh = eff_wnd >> 1; pcb->ssthresh = eff_wnd >> 1;
if(pcb->ssthresh < pcb->mss) { if (pcb->ssthresh < pcb->mss) {
pcb->ssthresh = pcb->mss * 2; pcb->ssthresh = pcb->mss * 2;
} }
pcb->cwnd = pcb->mss; pcb->cwnd = pcb->mss;
@ -518,7 +518,7 @@ tcp_slowtmr(void)
} }
/* Check if this PCB has stayed too long in FIN-WAIT-2 */ /* Check if this PCB has stayed too long in FIN-WAIT-2 */
if (pcb->state == FIN_WAIT_2) { if (pcb->state == FIN_WAIT_2) {
if((u32_t)(tcp_ticks - pcb->tmr) > if ((u32_t)(tcp_ticks - pcb->tmr) >
TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) { TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
++pcb_remove; ++pcb_remove;
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n")); DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
@ -529,7 +529,7 @@ tcp_slowtmr(void)
inactive for too long, will drop the data (it will eventually inactive for too long, will drop the data (it will eventually
be retransmitted). */ be retransmitted). */
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
if(pcb->ooseq != NULL && if (pcb->ooseq != NULL &&
(u32_t)tcp_ticks - pcb->tmr >= (u32_t)tcp_ticks - pcb->tmr >=
pcb->rto * TCP_OOSEQ_TIMEOUT) { pcb->rto * TCP_OOSEQ_TIMEOUT) {
tcp_segs_free(pcb->ooseq); tcp_segs_free(pcb->ooseq);
@ -539,8 +539,8 @@ tcp_slowtmr(void)
#endif /* TCP_QUEUE_OOSEQ */ #endif /* TCP_QUEUE_OOSEQ */
/* Check if this PCB has stayed too long in SYN-RCVD */ /* Check if this PCB has stayed too long in SYN-RCVD */
if(pcb->state == SYN_RCVD) { if (pcb->state == SYN_RCVD) {
if((u32_t)(tcp_ticks - pcb->tmr) > if ((u32_t)(tcp_ticks - pcb->tmr) >
TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) { TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
++pcb_remove; ++pcb_remove;
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n")); DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
@ -549,10 +549,10 @@ tcp_slowtmr(void)
/* If the PCB should be removed, do it. */ /* If the PCB should be removed, do it. */
if(pcb_remove) { if (pcb_remove) {
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
/* Remove PCB from tcp_active_pcbs list. */ /* Remove PCB from tcp_active_pcbs list. */
if(prev != NULL) { if (prev != NULL) {
LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs); LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);
prev->next = pcb->next; prev->next = pcb->next;
} else { } else {
@ -570,11 +570,11 @@ tcp_slowtmr(void)
/* We check if we should poll the connection. */ /* We check if we should poll the connection. */
++pcb->polltmr; ++pcb->polltmr;
if(pcb->polltmr >= pcb->pollinterval) { if (pcb->polltmr >= pcb->pollinterval) {
pcb->polltmr = 0; pcb->polltmr = 0;
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n")); DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
TCP_EVENT_POLL(pcb, err); TCP_EVENT_POLL(pcb, err);
if(err == ERR_OK) { if (err == ERR_OK) {
tcp_output(pcb); tcp_output(pcb);
} }
} }
@ -588,22 +588,22 @@ tcp_slowtmr(void)
/* Steps through all of the TIME-WAIT PCBs. */ /* Steps through all of the TIME-WAIT PCBs. */
prev = NULL; prev = NULL;
pcb = tcp_tw_pcbs; pcb = tcp_tw_pcbs;
while(pcb != NULL) { while (pcb != NULL) {
LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT); LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
pcb_remove = 0; pcb_remove = 0;
/* Check if this PCB has stayed long enough in TIME-WAIT */ /* Check if this PCB has stayed long enough in TIME-WAIT */
if((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) { if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
++pcb_remove; ++pcb_remove;
} }
/* If the PCB should be removed, do it. */ /* If the PCB should be removed, do it. */
if(pcb_remove) { if (pcb_remove) {
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
/* Remove PCB from tcp_tw_pcbs list. */ /* Remove PCB from tcp_tw_pcbs list. */
if(prev != NULL) { if (prev != NULL) {
LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs); LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);
prev->next = pcb->next; prev->next = pcb->next;
} else { } else {
@ -634,7 +634,7 @@ tcp_fasttmr(void)
/* send delayed ACKs */ /* send delayed ACKs */
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->flags & TF_ACK_DELAY) { if (pcb->flags & TF_ACK_DELAY) {
DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n")); DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
tcp_ack_now(pcb); tcp_ack_now(pcb);
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
@ -655,7 +655,7 @@ tcp_segs_free(struct tcp_seg *seg)
u8_t count = 0; u8_t count = 0;
struct tcp_seg *next; struct tcp_seg *next;
again: again:
if(seg != NULL) { if (seg != NULL) {
next = seg->next; next = seg->next;
count += tcp_seg_free(seg); count += tcp_seg_free(seg);
seg = next; seg = next;
@ -676,8 +676,8 @@ tcp_seg_free(struct tcp_seg *seg)
{ {
u8_t count = 0; u8_t count = 0;
if(seg != NULL) { if (seg != NULL) {
if(seg->p == NULL) { if (seg->p == NULL) {
memp_free(MEMP_TCP_SEG, seg); memp_free(MEMP_TCP_SEG, seg);
} else { } else {
count = pbuf_free(seg->p); count = pbuf_free(seg->p);
@ -716,7 +716,7 @@ tcp_seg_copy(struct tcp_seg *seg)
struct tcp_seg *cseg; struct tcp_seg *cseg;
cseg = memp_malloc(MEMP_TCP_SEG); cseg = memp_malloc(MEMP_TCP_SEG);
if(cseg == NULL) { if (cseg == NULL) {
return NULL; return NULL;
} }
memcpy((char *)cseg, (const char *)seg, sizeof(struct tcp_seg)); memcpy((char *)cseg, (const char *)seg, sizeof(struct tcp_seg));
@ -729,9 +729,9 @@ static err_t
tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{ {
arg = arg; arg = arg;
if(p != NULL) { if (p != NULL) {
pbuf_free(p); pbuf_free(p);
} else if(err == ERR_OK) { } else if (err == ERR_OK) {
return tcp_close(pcb); return tcp_close(pcb);
} }
return ERR_OK; return ERR_OK;
@ -753,7 +753,7 @@ tcp_kill_prio(u8_t prio)
inactivity = 0; inactivity = 0;
inactive = NULL; inactive = NULL;
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->prio <= prio && if (pcb->prio <= prio &&
pcb->prio <= mprio && pcb->prio <= mprio &&
(u32_t)(tcp_ticks - pcb->tmr) >= inactivity) { (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
inactivity = tcp_ticks - pcb->tmr; inactivity = tcp_ticks - pcb->tmr;
@ -761,7 +761,7 @@ tcp_kill_prio(u8_t prio)
mprio = pcb->prio; mprio = pcb->prio;
} }
} }
if(inactive != NULL) { if (inactive != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB 0x%p (%ld)\n", DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB 0x%p (%ld)\n",
(void *)inactive, inactivity)); (void *)inactive, inactivity));
tcp_abort(inactive); tcp_abort(inactive);
@ -778,12 +778,12 @@ tcp_kill_timewait(void)
inactivity = 0; inactivity = 0;
inactive = NULL; inactive = NULL;
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
if((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) { if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
inactivity = tcp_ticks - pcb->tmr; inactivity = tcp_ticks - pcb->tmr;
inactive = pcb; inactive = pcb;
} }
} }
if(inactive != NULL) { if (inactive != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB 0x%p (%ld)\n", DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB 0x%p (%ld)\n",
(void *)inactive, inactivity)); (void *)inactive, inactivity));
tcp_abort(inactive); tcp_abort(inactive);
@ -799,17 +799,17 @@ tcp_alloc(u8_t prio)
u32_t iss; u32_t iss;
pcb = memp_malloc(MEMP_TCP_PCB); pcb = memp_malloc(MEMP_TCP_PCB);
if(pcb == NULL) { if (pcb == NULL) {
/* Try killing oldest connection in TIME-WAIT. */ /* Try killing oldest connection in TIME-WAIT. */
DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n")); DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));
tcp_kill_timewait(); tcp_kill_timewait();
pcb = memp_malloc(MEMP_TCP_PCB); pcb = memp_malloc(MEMP_TCP_PCB);
if(pcb == NULL) { if (pcb == NULL) {
tcp_kill_prio(prio); tcp_kill_prio(prio);
pcb = memp_malloc(MEMP_TCP_PCB); pcb = memp_malloc(MEMP_TCP_PCB);
} }
} }
if(pcb != NULL) { if (pcb != NULL) {
memset(pcb, 0, sizeof(struct tcp_pcb)); memset(pcb, 0, sizeof(struct tcp_pcb));
pcb->prio = TCP_PRIO_NORMAL; pcb->prio = TCP_PRIO_NORMAL;
pcb->snd_buf = TCP_SND_BUF; pcb->snd_buf = TCP_SND_BUF;
@ -963,21 +963,21 @@ tcp_accept(struct tcp_pcb *pcb,
void void
tcp_pcb_purge(struct tcp_pcb *pcb) tcp_pcb_purge(struct tcp_pcb *pcb)
{ {
if(pcb->state != CLOSED && if (pcb->state != CLOSED &&
pcb->state != TIME_WAIT && pcb->state != TIME_WAIT &&
pcb->state != LISTEN) { pcb->state != LISTEN) {
DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n")); DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));
#if TCP_DEBUG #if TCP_DEBUG
if(pcb->unsent != NULL) { if (pcb->unsent != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n")); DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));
} }
if(pcb->unacked != NULL) { if (pcb->unacked != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n")); DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));
} }
#if TCP_QUEUE_OOSEQ /* LW */ #if TCP_QUEUE_OOSEQ /* LW */
if(pcb->ooseq != NULL) { if (pcb->ooseq != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n")); DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));
} }
#endif #endif
@ -1010,7 +1010,7 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
/* if there is an outstanding delayed ACKs, send it */ /* if there is an outstanding delayed ACKs, send it */
if(pcb->state != TIME_WAIT && if (pcb->state != TIME_WAIT &&
pcb->state != LISTEN && pcb->state != LISTEN &&
pcb->flags & TF_ACK_DELAY) { pcb->flags & TF_ACK_DELAY) {
pcb->flags |= TF_ACK_NOW; pcb->flags |= TF_ACK_NOW;
@ -1073,7 +1073,7 @@ void
tcp_debug_print_state(enum tcp_state s) tcp_debug_print_state(enum tcp_state s)
{ {
DEBUGF(TCP_DEBUG, ("State: ")); DEBUGF(TCP_DEBUG, ("State: "));
switch(s) { switch (s) {
case CLOSED: case CLOSED:
DEBUGF(TCP_DEBUG, ("CLOSED\n")); DEBUGF(TCP_DEBUG, ("CLOSED\n"));
break; break;
@ -1113,22 +1113,22 @@ tcp_debug_print_state(enum tcp_state s)
void void
tcp_debug_print_flags(u8_t flags) tcp_debug_print_flags(u8_t flags)
{ {
if(flags & TCP_FIN) { if (flags & TCP_FIN) {
DEBUGF(TCP_DEBUG, ("FIN ")); DEBUGF(TCP_DEBUG, ("FIN "));
} }
if(flags & TCP_SYN) { if (flags & TCP_SYN) {
DEBUGF(TCP_DEBUG, ("SYN ")); DEBUGF(TCP_DEBUG, ("SYN "));
} }
if(flags & TCP_RST) { if (flags & TCP_RST) {
DEBUGF(TCP_DEBUG, ("RST ")); DEBUGF(TCP_DEBUG, ("RST "));
} }
if(flags & TCP_PSH) { if (flags & TCP_PSH) {
DEBUGF(TCP_DEBUG, ("PSH ")); DEBUGF(TCP_DEBUG, ("PSH "));
} }
if(flags & TCP_ACK) { if (flags & TCP_ACK) {
DEBUGF(TCP_DEBUG, ("ACK ")); DEBUGF(TCP_DEBUG, ("ACK "));
} }
if(flags & TCP_URG) { if (flags & TCP_URG) {
DEBUGF(TCP_DEBUG, ("URG ")); DEBUGF(TCP_DEBUG, ("URG "));
} }
} }

View File

@ -125,14 +125,14 @@ tcp_input(struct pbuf *p, struct netif *inp)
} }
/* Don't even process incoming broadcasts/multicasts. */ /* Don't even process incoming broadcasts/multicasts. */
if(ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) || if (ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) ||
ip_addr_ismulticast(&(iphdr->dest))) { ip_addr_ismulticast(&(iphdr->dest))) {
pbuf_free(p); pbuf_free(p);
return; return;
} }
/* Verify TCP checksum. */ /* Verify TCP checksum. */
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest), (struct ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len) != 0) { IP_PROTO_TCP, p->tot_len) != 0) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04x\n", inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04x\n", inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
@ -173,7 +173,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED); LWIP_ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT); LWIP_ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN); LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN);
if(pcb->remote_port == tcphdr->src && if (pcb->remote_port == tcphdr->src &&
pcb->local_port == tcphdr->dest && pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) && ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) { ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
@ -182,7 +182,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
lookups will be faster (we exploit locality in TCP segment lookups will be faster (we exploit locality in TCP segment
arrivals). */ arrivals). */
LWIP_ASSERT("tcp_input: pcb->next != pcb (before cache)", pcb->next != pcb); LWIP_ASSERT("tcp_input: pcb->next != pcb (before cache)", pcb->next != pcb);
if(prev != NULL) { if (prev != NULL) {
prev->next = pcb->next; prev->next = pcb->next;
pcb->next = tcp_active_pcbs; pcb->next = tcp_active_pcbs;
tcp_active_pcbs = pcb; tcp_active_pcbs = pcb;
@ -199,7 +199,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_ASSERT("tcp_input: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT); LWIP_ASSERT("tcp_input: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
if(pcb->remote_port == tcphdr->src && if (pcb->remote_port == tcphdr->src &&
pcb->local_port == tcphdr->dest && pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) && ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) { ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) {
@ -217,13 +217,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
are LISTENing for incoming connections. */ are LISTENing for incoming connections. */
prev = NULL; prev = NULL;
for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if((ip_addr_isany(&(lpcb->local_ip)) || if ((ip_addr_isany(&(lpcb->local_ip)) ||
ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) && ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) &&
lpcb->local_port == tcphdr->dest) { lpcb->local_port == tcphdr->dest) {
/* Move this PCB to the front of the list so that subsequent /* Move this PCB to the front of the list so that subsequent
lookups will be faster (we exploit locality in TCP segment lookups will be faster (we exploit locality in TCP segment
arrivals). */ arrivals). */
if(prev != NULL) { if (prev != NULL) {
((struct tcp_pcb_listen *)prev)->next = lpcb->next; ((struct tcp_pcb_listen *)prev)->next = lpcb->next;
/* our successor is the remainder of the listening list */ /* our successor is the remainder of the listening list */
lpcb->next = tcp_listen_pcbs; lpcb->next = tcp_listen_pcbs;
@ -247,7 +247,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
#endif /* TCP_INPUT_DEBUG */ #endif /* TCP_INPUT_DEBUG */
if(pcb != NULL) { if (pcb != NULL) {
/* The incoming segment belongs to a connection. */ /* The incoming segment belongs to a connection. */
#if TCP_INPUT_DEBUG #if TCP_INPUT_DEBUG
#if TCP_DEBUG #if TCP_DEBUG
@ -270,8 +270,8 @@ tcp_input(struct pbuf *p, struct netif *inp)
tcp_input_pcb = NULL; tcp_input_pcb = NULL;
/* A return value of ERR_ABRT means that tcp_abort() was called /* A return value of ERR_ABRT means that tcp_abort() was called
and that the pcb has been freed. If so, we don't do anything. */ and that the pcb has been freed. If so, we don't do anything. */
if(err != ERR_ABRT) { if (err != ERR_ABRT) {
if(recv_flags & TF_RESET) { if (recv_flags & TF_RESET) {
/* TF_RESET means that the connection was reset by the other /* TF_RESET means that the connection was reset by the other
end. We then call the error callback to inform the end. We then call the error callback to inform the
application that the connection is dead before we application that the connection is dead before we
@ -279,7 +279,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_RST); TCP_EVENT_ERR(pcb->errf, pcb->callback_arg, ERR_RST);
tcp_pcb_remove(&tcp_active_pcbs, pcb); tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb); memp_free(MEMP_TCP_PCB, pcb);
} else if(recv_flags & TF_CLOSED) { } else if (recv_flags & TF_CLOSED) {
/* The connection has been closed and we will deallocate the /* The connection has been closed and we will deallocate the
PCB. */ PCB. */
tcp_pcb_remove(&tcp_active_pcbs, pcb); tcp_pcb_remove(&tcp_active_pcbs, pcb);
@ -289,22 +289,22 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* If the application has registered a "sent" function to be /* If the application has registered a "sent" function to be
called when new send buffer space is available, we call it called when new send buffer space is available, we call it
now. */ now. */
if(pcb->acked > 0) { if (pcb->acked > 0) {
TCP_EVENT_SENT(pcb, pcb->acked, err); TCP_EVENT_SENT(pcb, pcb->acked, err);
} }
if(recv_data != NULL) { if (recv_data != NULL) {
/* Notify application that data has been received. */ /* Notify application that data has been received. */
TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err); TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err);
} }
/* If a FIN segment was received, we call the callback /* If a FIN segment was received, we call the callback
function with a NULL buffer to indicate EOF. */ function with a NULL buffer to indicate EOF. */
if(recv_flags & TF_GOT_FIN) { if (recv_flags & TF_GOT_FIN) {
TCP_EVENT_RECV(pcb, NULL, ERR_OK, err); TCP_EVENT_RECV(pcb, NULL, ERR_OK, err);
} }
/* If there were no errors, we try to send something out. */ /* If there were no errors, we try to send something out. */
if(err == ERR_OK) { if (err == ERR_OK) {
tcp_output(pcb); tcp_output(pcb);
} }
} }
@ -327,7 +327,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* If no matching PCB was found, send a TCP RST (reset) to the /* If no matching PCB was found, send a TCP RST (reset) to the
sender. */ sender. */
DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n")); DEBUGF(TCP_RST_DEBUG, ("tcp_input: no PCB match found, resetting.\n"));
if(!(TCPH_FLAGS(tcphdr) & TCP_RST)) { if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) {
#ifdef TCP_STATS #ifdef TCP_STATS
++lwip_stats.tcp.proterr; ++lwip_stats.tcp.proterr;
++lwip_stats.tcp.drop; ++lwip_stats.tcp.drop;
@ -357,20 +357,20 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
/* In the LISTEN state, we check for incoming SYN segments, /* In the LISTEN state, we check for incoming SYN segments,
creates a new PCB, and responds with a SYN|ACK. */ creates a new PCB, and responds with a SYN|ACK. */
if(flags & TCP_ACK) { if (flags & TCP_ACK) {
/* For incoming segments with the ACK flag set, respond with a /* For incoming segments with the ACK flag set, respond with a
RST. */ RST. */
DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n")); DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
tcp_rst(ackno + 1, seqno + tcplen, tcp_rst(ackno + 1, seqno + tcplen,
&(iphdr->dest), &(iphdr->src), &(iphdr->dest), &(iphdr->src),
tcphdr->dest, tcphdr->src); tcphdr->dest, tcphdr->src);
} else if(flags & TCP_SYN) { } else if (flags & TCP_SYN) {
DEBUGF(DEMO_DEBUG, ("TCP connection request %d -> %d.\n", tcphdr->src, tcphdr->dest)); DEBUGF(DEMO_DEBUG, ("TCP connection request %d -> %d.\n", tcphdr->src, tcphdr->dest));
npcb = tcp_alloc(pcb->prio); npcb = tcp_alloc(pcb->prio);
/* If a new PCB could not be created (probably due to lack of memory), /* If a new PCB could not be created (probably due to lack of memory),
we don't do anything, but rely on the sender will retransmit the we don't do anything, but rely on the sender will retransmit the
SYN at a time when we have more memory available. */ SYN at a time when we have more memory available. */
if(npcb == NULL) { if (npcb == NULL) {
DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n")); DEBUGF(TCP_DEBUG, ("tcp_listen_input: could not allocate PCB\n"));
#ifdef TCP_STATS #ifdef TCP_STATS
++lwip_stats.tcp.memerr; ++lwip_stats.tcp.memerr;
@ -420,10 +420,10 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
static err_t static err_t
tcp_timewait_input(struct tcp_pcb *pcb) tcp_timewait_input(struct tcp_pcb *pcb)
{ {
if(TCP_SEQ_GT(seqno + tcplen, pcb->rcv_nxt)) { if (TCP_SEQ_GT(seqno + tcplen, pcb->rcv_nxt)) {
pcb->rcv_nxt = seqno + tcplen; pcb->rcv_nxt = seqno + tcplen;
} }
if(tcplen > 0) { if (tcplen > 0) {
tcp_ack_now(pcb); tcp_ack_now(pcb);
} }
return tcp_output(pcb); return tcp_output(pcb);
@ -448,20 +448,20 @@ tcp_process(struct tcp_pcb *pcb)
err = ERR_OK; err = ERR_OK;
/* Process incoming RST segments. */ /* Process incoming RST segments. */
if(flags & TCP_RST) { if (flags & TCP_RST) {
/* First, determine if the reset is acceptable. */ /* First, determine if the reset is acceptable. */
if(pcb->state == SYN_SENT) { if (pcb->state == SYN_SENT) {
if(ackno == pcb->snd_nxt) { if (ackno == pcb->snd_nxt) {
acceptable = 1; acceptable = 1;
} }
} else { } else {
if(TCP_SEQ_GEQ(seqno, pcb->rcv_nxt) && if (TCP_SEQ_GEQ(seqno, pcb->rcv_nxt) &&
TCP_SEQ_LEQ(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) { TCP_SEQ_LEQ(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) {
acceptable = 1; acceptable = 1;
} }
} }
if(acceptable) { if (acceptable) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: Connection RESET\n")); DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: Connection RESET\n"));
LWIP_ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED); LWIP_ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED);
recv_flags = TF_RESET; recv_flags = TF_RESET;
@ -480,11 +480,11 @@ tcp_process(struct tcp_pcb *pcb)
pcb->tmr = tcp_ticks; pcb->tmr = tcp_ticks;
/* Do different things depending on the TCP state. */ /* Do different things depending on the TCP state. */
switch(pcb->state) { switch (pcb->state) {
case SYN_SENT: case SYN_SENT:
DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %lu pcb->snd_nxt %lu unacked %lu\n", ackno, DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %lu pcb->snd_nxt %lu unacked %lu\n", ackno,
pcb->snd_nxt, ntohl(pcb->unacked->tcphdr->seqno))); pcb->snd_nxt, ntohl(pcb->unacked->tcphdr->seqno)));
if(flags & (TCP_ACK | TCP_SYN) && if (flags & (TCP_ACK | TCP_SYN) &&
ackno == ntohl(pcb->unacked->tcphdr->seqno) + 1) { ackno == ntohl(pcb->unacked->tcphdr->seqno) + 1) {
pcb->rcv_nxt = seqno + 1; pcb->rcv_nxt = seqno + 1;
pcb->lastack = ackno; pcb->lastack = ackno;
@ -507,16 +507,16 @@ tcp_process(struct tcp_pcb *pcb)
} }
break; break;
case SYN_RCVD: case SYN_RCVD:
if(flags & TCP_ACK && if (flags & TCP_ACK &&
!(flags & TCP_RST)) { !(flags & TCP_RST)) {
if(TCP_SEQ_LT(pcb->lastack, ackno) && if (TCP_SEQ_LT(pcb->lastack, ackno) &&
TCP_SEQ_LEQ(ackno, pcb->snd_nxt)) { TCP_SEQ_LEQ(ackno, pcb->snd_nxt)) {
pcb->state = ESTABLISHED; pcb->state = ESTABLISHED;
DEBUGF(DEMO_DEBUG, ("TCP connection established %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest)); DEBUGF(DEMO_DEBUG, ("TCP connection established %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
LWIP_ASSERT("pcb->accept != NULL", pcb->accept != NULL); LWIP_ASSERT("pcb->accept != NULL", pcb->accept != NULL);
/* Call the accept function. */ /* Call the accept function. */
TCP_EVENT_ACCEPT(pcb, ERR_OK, err); TCP_EVENT_ACCEPT(pcb, ERR_OK, err);
if(err != ERR_OK) { if (err != ERR_OK) {
/* If the accept function returns with an error, we abort /* If the accept function returns with an error, we abort
the connection. */ the connection. */
tcp_abort(pcb); tcp_abort(pcb);
@ -533,15 +533,15 @@ tcp_process(struct tcp_pcb *pcb)
/* FALLTHROUGH */ /* FALLTHROUGH */
case ESTABLISHED: case ESTABLISHED:
tcp_receive(pcb); tcp_receive(pcb);
if(flags & TCP_FIN) { if (flags & TCP_FIN) {
tcp_ack_now(pcb); tcp_ack_now(pcb);
pcb->state = CLOSE_WAIT; pcb->state = CLOSE_WAIT;
} }
break; break;
case FIN_WAIT_1: case FIN_WAIT_1:
tcp_receive(pcb); tcp_receive(pcb);
if(flags & TCP_FIN) { if (flags & TCP_FIN) {
if(flags & TCP_ACK && ackno == pcb->snd_nxt) { if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
DEBUGF(DEMO_DEBUG, DEBUGF(DEMO_DEBUG,
("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest)); ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
tcp_ack_now(pcb); tcp_ack_now(pcb);
@ -553,13 +553,13 @@ tcp_process(struct tcp_pcb *pcb)
tcp_ack_now(pcb); tcp_ack_now(pcb);
pcb->state = CLOSING; pcb->state = CLOSING;
} }
} else if(flags & TCP_ACK && ackno == pcb->snd_nxt) { } else if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
pcb->state = FIN_WAIT_2; pcb->state = FIN_WAIT_2;
} }
break; break;
case FIN_WAIT_2: case FIN_WAIT_2:
tcp_receive(pcb); tcp_receive(pcb);
if(flags & TCP_FIN) { if (flags & TCP_FIN) {
DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest)); DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
tcp_ack_now(pcb); tcp_ack_now(pcb);
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
@ -570,7 +570,7 @@ tcp_process(struct tcp_pcb *pcb)
break; break;
case CLOSING: case CLOSING:
tcp_receive(pcb); tcp_receive(pcb);
if(flags & TCP_ACK && ackno == pcb->snd_nxt) { if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest)); DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
tcp_ack_now(pcb); tcp_ack_now(pcb);
tcp_pcb_purge(pcb); tcp_pcb_purge(pcb);
@ -581,7 +581,7 @@ tcp_process(struct tcp_pcb *pcb)
break; break;
case LAST_ACK: case LAST_ACK:
tcp_receive(pcb); tcp_receive(pcb);
if(flags & TCP_ACK && ackno == pcb->snd_nxt) { if (flags & TCP_ACK && ackno == pcb->snd_nxt) {
DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest)); DEBUGF(DEMO_DEBUG, ("TCP connection closed %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
pcb->state = CLOSED; pcb->state = CLOSED;
recv_flags = TF_CLOSED; recv_flags = TF_CLOSED;
@ -619,11 +619,11 @@ tcp_receive(struct tcp_pcb *pcb)
u32_t right_wnd_edge; u32_t right_wnd_edge;
if(flags & TCP_ACK) { if (flags & TCP_ACK) {
right_wnd_edge = pcb->snd_wnd + pcb->snd_wl1; right_wnd_edge = pcb->snd_wnd + pcb->snd_wl1;
/* Update window. */ /* Update window. */
if(TCP_SEQ_LT(pcb->snd_wl1, seqno) || if (TCP_SEQ_LT(pcb->snd_wl1, seqno) ||
(pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) || (pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) ||
(pcb->snd_wl2 == ackno && tcphdr->wnd > pcb->snd_wnd)) { (pcb->snd_wl2 == ackno && tcphdr->wnd > pcb->snd_wnd)) {
pcb->snd_wnd = tcphdr->wnd; pcb->snd_wnd = tcphdr->wnd;
@ -632,7 +632,7 @@ tcp_receive(struct tcp_pcb *pcb)
DEBUGF(TCP_WND_DEBUG, ("tcp_receive: window update %lu\n", pcb->snd_wnd)); DEBUGF(TCP_WND_DEBUG, ("tcp_receive: window update %lu\n", pcb->snd_wnd));
#if TCP_WND_DEBUG #if TCP_WND_DEBUG
} else { } else {
if(pcb->snd_wnd != tcphdr->wnd) { if (pcb->snd_wnd != tcphdr->wnd) {
DEBUGF(TCP_WND_DEBUG, ("tcp_receive: no window update lastack %lu snd_max %lu ackno %lu wl1 %lu seqno %lu wl2 %lu\n", DEBUGF(TCP_WND_DEBUG, ("tcp_receive: no window update lastack %lu snd_max %lu ackno %lu wl1 %lu seqno %lu wl2 %lu\n",
pcb->lastack, pcb->snd_max, ackno, pcb->snd_wl1, seqno, pcb->snd_wl2)); pcb->lastack, pcb->snd_max, ackno, pcb->snd_wl1, seqno, pcb->snd_wl2));
} }
@ -640,13 +640,13 @@ tcp_receive(struct tcp_pcb *pcb)
} }
if(pcb->lastack == ackno) { if (pcb->lastack == ackno) {
pcb->acked = 0; pcb->acked = 0;
if(pcb->snd_wl1 + pcb->snd_wnd == right_wnd_edge){ if (pcb->snd_wl1 + pcb->snd_wnd == right_wnd_edge){
++pcb->dupacks; ++pcb->dupacks;
if(pcb->dupacks >= 3 && pcb->unacked != NULL) { if (pcb->dupacks >= 3 && pcb->unacked != NULL) {
if(!(pcb->flags & TF_INFR)) { if (!(pcb->flags & TF_INFR)) {
/* This is fast retransmit. Retransmit the first unacked segment. */ /* This is fast retransmit. Retransmit the first unacked segment. */
DEBUGF(TCP_FR_DEBUG, ("tcp_receive: dupacks %d (%lu), fast retransmit %lu\n", DEBUGF(TCP_FR_DEBUG, ("tcp_receive: dupacks %d (%lu), fast retransmit %lu\n",
pcb->dupacks, pcb->lastack, pcb->dupacks, pcb->lastack,
@ -662,7 +662,7 @@ tcp_receive(struct tcp_pcb *pcb)
} else { } else {
/* Inflate the congestion window, but not if it means that /* Inflate the congestion window, but not if it means that
the value overflows. */ the value overflows. */
if((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) { if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
pcb->cwnd += pcb->mss; pcb->cwnd += pcb->mss;
} }
} }
@ -671,14 +671,14 @@ tcp_receive(struct tcp_pcb *pcb)
DEBUGF(TCP_FR_DEBUG, ("tcp_receive: dupack averted %lu %lu\n", DEBUGF(TCP_FR_DEBUG, ("tcp_receive: dupack averted %lu %lu\n",
pcb->snd_wl1 + pcb->snd_wnd, right_wnd_edge)); pcb->snd_wl1 + pcb->snd_wnd, right_wnd_edge));
} }
} else if(TCP_SEQ_LT(pcb->lastack, ackno) && } else if (TCP_SEQ_LT(pcb->lastack, ackno) &&
TCP_SEQ_LEQ(ackno, pcb->snd_max)) { TCP_SEQ_LEQ(ackno, pcb->snd_max)) {
/* We come here when the ACK acknowledges new data. */ /* We come here when the ACK acknowledges new data. */
/* Reset the "IN Fast Retransmit" flag, since we are no longer /* Reset the "IN Fast Retransmit" flag, since we are no longer
in fast retransmit. Also reset the congestion window to the in fast retransmit. Also reset the congestion window to the
slow start threshold. */ slow start threshold. */
if(pcb->flags & TF_INFR) { if (pcb->flags & TF_INFR) {
pcb->flags &= ~TF_INFR; pcb->flags &= ~TF_INFR;
pcb->cwnd = pcb->ssthresh; pcb->cwnd = pcb->ssthresh;
} }
@ -699,15 +699,15 @@ tcp_receive(struct tcp_pcb *pcb)
/* Update the congestion control variables (cwnd and /* Update the congestion control variables (cwnd and
ssthresh). */ ssthresh). */
if(pcb->state >= ESTABLISHED) { if (pcb->state >= ESTABLISHED) {
if(pcb->cwnd < pcb->ssthresh) { if (pcb->cwnd < pcb->ssthresh) {
if((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) { if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
pcb->cwnd += pcb->mss; pcb->cwnd += pcb->mss;
} }
DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %u\n", pcb->cwnd)); DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %u\n", pcb->cwnd));
} else { } else {
u16_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd); u16_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd);
if(new_cwnd > pcb->cwnd) { if (new_cwnd > pcb->cwnd) {
pcb->cwnd = new_cwnd; pcb->cwnd = new_cwnd;
} }
DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %u\n", pcb->cwnd)); DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %u\n", pcb->cwnd));
@ -722,7 +722,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* Remove segment from the unacknowledged list if the incoming /* Remove segment from the unacknowledged list if the incoming
ACK acknowlegdes them. */ ACK acknowlegdes them. */
while(pcb->unacked != NULL && while (pcb->unacked != NULL &&
TCP_SEQ_LEQ(ntohl(pcb->unacked->tcphdr->seqno) + TCP_SEQ_LEQ(ntohl(pcb->unacked->tcphdr->seqno) +
TCP_TCPLEN(pcb->unacked), ackno)) { TCP_TCPLEN(pcb->unacked), ackno)) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %lu:%lu from pcb->unacked\n", DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %lu:%lu from pcb->unacked\n",
@ -738,7 +738,7 @@ tcp_receive(struct tcp_pcb *pcb)
tcp_seg_free(next); tcp_seg_free(next);
DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unacked)\n", pcb->snd_queuelen)); DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unacked)\n", pcb->snd_queuelen));
if(pcb->snd_queuelen != 0) { if (pcb->snd_queuelen != 0) {
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL || LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL); pcb->unsent != NULL);
} }
@ -752,7 +752,7 @@ tcp_receive(struct tcp_pcb *pcb)
rationale is that lwIP puts all outstanding segments on the rationale is that lwIP puts all outstanding segments on the
->unsent list after a retransmission, so these segments may ->unsent list after a retransmission, so these segments may
in fact have been sent once. */ in fact have been sent once. */
while(pcb->unsent != NULL && while (pcb->unsent != NULL &&
TCP_SEQ_LEQ(ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent), TCP_SEQ_LEQ(ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent),
ackno) && ackno) &&
TCP_SEQ_LEQ(ackno, pcb->snd_max)) { TCP_SEQ_LEQ(ackno, pcb->snd_max)) {
@ -767,12 +767,12 @@ tcp_receive(struct tcp_pcb *pcb)
pcb->snd_queuelen -= pbuf_clen(next->p); pcb->snd_queuelen -= pbuf_clen(next->p);
tcp_seg_free(next); tcp_seg_free(next);
DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unsent)\n", pcb->snd_queuelen)); DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unsent)\n", pcb->snd_queuelen));
if(pcb->snd_queuelen != 0) { if (pcb->snd_queuelen != 0) {
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL || LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL); pcb->unsent != NULL);
} }
if(pcb->unsent != NULL) { if (pcb->unsent != NULL) {
pcb->snd_nxt = htonl(pcb->unsent->tcphdr->seqno); pcb->snd_nxt = htonl(pcb->unsent->tcphdr->seqno);
} }
} }
@ -785,7 +785,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* RTT estimation calculations. This is done by checking if the /* RTT estimation calculations. This is done by checking if the
incoming segment acknowledges the segment we use to take a incoming segment acknowledges the segment we use to take a
round-trip time measurement. */ round-trip time measurement. */
if(pcb->rttest && TCP_SEQ_LT(pcb->rtseq, ackno)) { if (pcb->rttest && TCP_SEQ_LT(pcb->rtseq, ackno)) {
m = tcp_ticks - pcb->rttest; m = tcp_ticks - pcb->rttest;
DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: experienced rtt %d ticks (%d msec).\n", DEBUGF(TCP_RTO_DEBUG, ("tcp_receive: experienced rtt %d ticks (%d msec).\n",
@ -794,7 +794,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* This is taken directly from VJs original code in his paper */ /* This is taken directly from VJs original code in his paper */
m = m - (pcb->sa >> 3); m = m - (pcb->sa >> 3);
pcb->sa += m; pcb->sa += m;
if(m < 0) { if (m < 0) {
m = -m; m = -m;
} }
m = m - (pcb->sv >> 2); m = m - (pcb->sv >> 2);
@ -810,7 +810,7 @@ tcp_receive(struct tcp_pcb *pcb)
/* If the incoming segment contains data, we must process it /* If the incoming segment contains data, we must process it
further. */ further. */
if(tcplen > 0) { if (tcplen > 0) {
/* This code basically does three things: /* This code basically does three things:
+) If the incoming segment contains data that is the next +) If the incoming segment contains data that is the next
@ -839,8 +839,8 @@ tcp_receive(struct tcp_pcb *pcb)
this if the sequence number of the incoming segment is less this if the sequence number of the incoming segment is less
than rcv_nxt, and the sequence number plus the length of the than rcv_nxt, and the sequence number plus the length of the
segment is larger than rcv_nxt. */ segment is larger than rcv_nxt. */
if(TCP_SEQ_LT(seqno, pcb->rcv_nxt)){ if (TCP_SEQ_LT(seqno, pcb->rcv_nxt)){
if(TCP_SEQ_LT(pcb->rcv_nxt, seqno + tcplen)) { if (TCP_SEQ_LT(pcb->rcv_nxt, seqno + tcplen)) {
/* Trimming the first edge is done by pushing the payload /* Trimming the first edge is done by pushing the payload
pointer in the pbuf downwards. This is somewhat tricky since pointer in the pbuf downwards. This is somewhat tricky since
we do not want to discard the full contents of the pbuf up to we do not want to discard the full contents of the pbuf up to
@ -861,9 +861,9 @@ tcp_receive(struct tcp_pcb *pcb)
adjust the ->data pointer in the seg and the segment adjust the ->data pointer in the seg and the segment
length.*/ length.*/
off = pcb->rcv_nxt - seqno; off = pcb->rcv_nxt - seqno;
if(inseg.p->len < off) { if (inseg.p->len < off) {
p = inseg.p; p = inseg.p;
while(p->len < off) { while (p->len < off) {
off -= p->len; off -= p->len;
inseg.p->tot_len -= p->len; inseg.p->tot_len -= p->len;
p->len = 0; p->len = 0;
@ -889,14 +889,14 @@ tcp_receive(struct tcp_pcb *pcb)
/* The sequence number must be within the window (above rcv_nxt /* The sequence number must be within the window (above rcv_nxt
and below rcv_nxt + rcv_wnd) in order to be further and below rcv_nxt + rcv_wnd) in order to be further
processed. */ processed. */
if(TCP_SEQ_GEQ(seqno, pcb->rcv_nxt) && if (TCP_SEQ_GEQ(seqno, pcb->rcv_nxt) &&
TCP_SEQ_LT(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) { TCP_SEQ_LT(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) {
if(pcb->rcv_nxt == seqno) { if (pcb->rcv_nxt == seqno) {
/* The incoming segment is the next in sequence. We check if /* The incoming segment is the next in sequence. We check if
we have to trim the end of the segment and update rcv_nxt we have to trim the end of the segment and update rcv_nxt
and pass the data to the application. */ and pass the data to the application. */
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
if(pcb->ooseq != NULL && if (pcb->ooseq != NULL &&
TCP_SEQ_LEQ(pcb->ooseq->tcphdr->seqno, seqno + inseg.len)) { TCP_SEQ_LEQ(pcb->ooseq->tcphdr->seqno, seqno + inseg.len)) {
/* We have to trim the second edge of the incoming /* We have to trim the second edge of the incoming
segment. */ segment. */
@ -910,7 +910,7 @@ tcp_receive(struct tcp_pcb *pcb)
pcb->rcv_nxt += tcplen; pcb->rcv_nxt += tcplen;
/* Update the receiver's (our) window. */ /* Update the receiver's (our) window. */
if(pcb->rcv_wnd < tcplen) { if (pcb->rcv_wnd < tcplen) {
pcb->rcv_wnd = 0; pcb->rcv_wnd = 0;
} else { } else {
pcb->rcv_wnd -= tcplen; pcb->rcv_wnd -= tcplen;
@ -925,14 +925,14 @@ tcp_receive(struct tcp_pcb *pcb)
If the segment was a FIN, we set the TF_GOT_FIN flag that will If the segment was a FIN, we set the TF_GOT_FIN flag that will
be used to indicate to the application that the remote side has be used to indicate to the application that the remote side has
closed its end of the connection. */ closed its end of the connection. */
if(inseg.p->tot_len > 0) { if (inseg.p->tot_len > 0) {
recv_data = inseg.p; recv_data = inseg.p;
/* Since this pbuf now is the responsibility of the /* Since this pbuf now is the responsibility of the
application, we delete our reference to it so that we won't application, we delete our reference to it so that we won't
(mistakingly) deallocate it. */ (mistakingly) deallocate it. */
inseg.p = NULL; inseg.p = NULL;
} }
if(TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) { if (TCPH_FLAGS(inseg.tcphdr) & TCP_FIN) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: received FIN.")); DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: received FIN."));
recv_flags = TF_GOT_FIN; recv_flags = TF_GOT_FIN;
} }
@ -940,22 +940,22 @@ tcp_receive(struct tcp_pcb *pcb)
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
/* We now check if we have segments on the ->ooseq queue that /* We now check if we have segments on the ->ooseq queue that
is now in sequence. */ is now in sequence. */
while(pcb->ooseq != NULL && while (pcb->ooseq != NULL &&
pcb->ooseq->tcphdr->seqno == pcb->rcv_nxt) { pcb->ooseq->tcphdr->seqno == pcb->rcv_nxt) {
cseg = pcb->ooseq; cseg = pcb->ooseq;
seqno = pcb->ooseq->tcphdr->seqno; seqno = pcb->ooseq->tcphdr->seqno;
pcb->rcv_nxt += TCP_TCPLEN(cseg); pcb->rcv_nxt += TCP_TCPLEN(cseg);
if(pcb->rcv_wnd < TCP_TCPLEN(cseg)) { if (pcb->rcv_wnd < TCP_TCPLEN(cseg)) {
pcb->rcv_wnd = 0; pcb->rcv_wnd = 0;
} else { } else {
pcb->rcv_wnd -= TCP_TCPLEN(cseg); pcb->rcv_wnd -= TCP_TCPLEN(cseg);
} }
if(cseg->p->tot_len > 0) { if (cseg->p->tot_len > 0) {
/* Chain this pbuf onto the pbuf that we will pass to /* Chain this pbuf onto the pbuf that we will pass to
the application. */ the application. */
if(recv_data) { if (recv_data) {
pbuf_chain(recv_data, cseg->p); pbuf_chain(recv_data, cseg->p);
pbuf_free(cseg->p); pbuf_free(cseg->p);
} else { } else {
@ -963,7 +963,7 @@ tcp_receive(struct tcp_pcb *pcb)
} }
cseg->p = NULL; cseg->p = NULL;
} }
if(flags & TCP_FIN) { if (flags & TCP_FIN) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: dequeued FIN.")); DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: dequeued FIN."));
recv_flags = TF_GOT_FIN; recv_flags = TF_GOT_FIN;
} }
@ -983,7 +983,7 @@ tcp_receive(struct tcp_pcb *pcb)
tcp_ack_now(pcb); tcp_ack_now(pcb);
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
/* We queue the segment on the ->ooseq queue. */ /* We queue the segment on the ->ooseq queue. */
if(pcb->ooseq == NULL) { if (pcb->ooseq == NULL) {
pcb->ooseq = tcp_seg_copy(&inseg); pcb->ooseq = tcp_seg_copy(&inseg);
} else { } else {
/* If the queue is not empty, we walk through the queue and /* If the queue is not empty, we walk through the queue and
@ -1000,19 +1000,19 @@ tcp_receive(struct tcp_pcb *pcb)
prev = NULL; prev = NULL;
for(next = pcb->ooseq; next != NULL; next = next->next) { for(next = pcb->ooseq; next != NULL; next = next->next) {
if(seqno == next->tcphdr->seqno) { if (seqno == next->tcphdr->seqno) {
/* The sequence number of the incoming segment is the /* The sequence number of the incoming segment is the
same as the sequence number of the segment on same as the sequence number of the segment on
->ooseq. We check the lengths to see which one to ->ooseq. We check the lengths to see which one to
discard. */ discard. */
if(inseg.len > next->len) { if (inseg.len > next->len) {
/* The incoming segment is larger than the old /* The incoming segment is larger than the old
segment. We replace the old segment with the new segment. We replace the old segment with the new
one. */ one. */
cseg = tcp_seg_copy(&inseg); cseg = tcp_seg_copy(&inseg);
if(cseg != NULL) { if (cseg != NULL) {
cseg->next = next->next; cseg->next = next->next;
if(prev != NULL) { if (prev != NULL) {
prev->next = cseg; prev->next = cseg;
} else { } else {
pcb->ooseq = cseg; pcb->ooseq = cseg;
@ -1026,43 +1026,43 @@ tcp_receive(struct tcp_pcb *pcb)
break; break;
} }
} else { } else {
if(prev == NULL) { if (prev == NULL) {
if(TCP_SEQ_LT(seqno, next->tcphdr->seqno)) { if (TCP_SEQ_LT(seqno, next->tcphdr->seqno)) {
/* The sequence number of the incoming segment is lower /* The sequence number of the incoming segment is lower
than the sequence number of the first segment on the than the sequence number of the first segment on the
queue. We put the incoming segment first on the queue. We put the incoming segment first on the
queue. */ queue. */
if(TCP_SEQ_GT(seqno + inseg.len, next->tcphdr->seqno)) { if (TCP_SEQ_GT(seqno + inseg.len, next->tcphdr->seqno)) {
/* We need to trim the incoming segment. */ /* We need to trim the incoming segment. */
inseg.len = next->tcphdr->seqno - seqno; inseg.len = next->tcphdr->seqno - seqno;
pbuf_realloc(inseg.p, inseg.len); pbuf_realloc(inseg.p, inseg.len);
} }
cseg = tcp_seg_copy(&inseg); cseg = tcp_seg_copy(&inseg);
if(cseg != NULL) { if (cseg != NULL) {
cseg->next = next; cseg->next = next;
pcb->ooseq = cseg; pcb->ooseq = cseg;
} }
break; break;
} }
} else if(TCP_SEQ_LT(prev->tcphdr->seqno, seqno) && } else if (TCP_SEQ_LT(prev->tcphdr->seqno, seqno) &&
TCP_SEQ_LT(seqno, next->tcphdr->seqno)) { TCP_SEQ_LT(seqno, next->tcphdr->seqno)) {
/* The sequence number of the incoming segment is in /* The sequence number of the incoming segment is in
between the sequence numbers of the previous and between the sequence numbers of the previous and
the next segment on ->ooseq. We trim and insert the the next segment on ->ooseq. We trim and insert the
incoming segment and trim the previous segment, if incoming segment and trim the previous segment, if
needed. */ needed. */
if(TCP_SEQ_GT(seqno + inseg.len, next->tcphdr->seqno)) { if (TCP_SEQ_GT(seqno + inseg.len, next->tcphdr->seqno)) {
/* We need to trim the incoming segment. */ /* We need to trim the incoming segment. */
inseg.len = next->tcphdr->seqno - seqno; inseg.len = next->tcphdr->seqno - seqno;
pbuf_realloc(inseg.p, inseg.len); pbuf_realloc(inseg.p, inseg.len);
} }
cseg = tcp_seg_copy(&inseg); cseg = tcp_seg_copy(&inseg);
if(cseg != NULL) { if (cseg != NULL) {
cseg->next = next; cseg->next = next;
prev->next = cseg; prev->next = cseg;
if(TCP_SEQ_GT(prev->tcphdr->seqno + prev->len, seqno)) { if (TCP_SEQ_GT(prev->tcphdr->seqno + prev->len, seqno)) {
/* We need to trim the prev segment. */ /* We need to trim the prev segment. */
prev->len = seqno - prev->tcphdr->seqno; prev->len = seqno - prev->tcphdr->seqno;
pbuf_realloc(prev->p, prev->len); pbuf_realloc(prev->p, prev->len);
@ -1073,11 +1073,11 @@ tcp_receive(struct tcp_pcb *pcb)
/* If the "next" segment is the last segment on the /* If the "next" segment is the last segment on the
ooseq queue, we add the incoming segment to the end ooseq queue, we add the incoming segment to the end
of the list. */ of the list. */
if(next->next == NULL && if (next->next == NULL &&
TCP_SEQ_GT(seqno, next->tcphdr->seqno)) { TCP_SEQ_GT(seqno, next->tcphdr->seqno)) {
next->next = tcp_seg_copy(&inseg); next->next = tcp_seg_copy(&inseg);
if(next->next != NULL) { if (next->next != NULL) {
if(TCP_SEQ_GT(next->tcphdr->seqno + next->len, seqno)) { if (TCP_SEQ_GT(next->tcphdr->seqno + next->len, seqno)) {
/* We need to trim the last segment. */ /* We need to trim the last segment. */
next->len = seqno - next->tcphdr->seqno; next->len = seqno - next->tcphdr->seqno;
pbuf_realloc(next->p, next->len); pbuf_realloc(next->p, next->len);
@ -1096,7 +1096,7 @@ tcp_receive(struct tcp_pcb *pcb)
} else { } else {
/* Segments with length 0 is taken care of here. Segments that /* Segments with length 0 is taken care of here. Segments that
fall out of the window are ACKed. */ fall out of the window are ACKed. */
if(TCP_SEQ_GT(pcb->rcv_nxt, seqno) || if (TCP_SEQ_GT(pcb->rcv_nxt, seqno) ||
TCP_SEQ_GEQ(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) { TCP_SEQ_GEQ(seqno, pcb->rcv_nxt + pcb->rcv_wnd)) {
tcp_ack_now(pcb); tcp_ack_now(pcb);
} }
@ -1121,16 +1121,16 @@ tcp_parseopt(struct tcp_pcb *pcb)
opts = (u8_t *)tcphdr + TCP_HLEN; opts = (u8_t *)tcphdr + TCP_HLEN;
/* Parse the TCP MSS option, if present. */ /* Parse the TCP MSS option, if present. */
if((TCPH_OFFSET(tcphdr) & 0xf0) > 0x50) { if ((TCPH_OFFSET(tcphdr) & 0xf0) > 0x50) {
for(c = 0; c < ((TCPH_OFFSET(tcphdr) >> 4) - 5) << 2 ;) { for(c = 0; c < ((TCPH_OFFSET(tcphdr) >> 4) - 5) << 2 ;) {
opt = opts[c]; opt = opts[c];
if(opt == 0x00) { if (opt == 0x00) {
/* End of options. */ /* End of options. */
break; break;
} else if(opt == 0x01) { } else if (opt == 0x01) {
++c; ++c;
/* NOP option. */ /* NOP option. */
} else if(opt == 0x02 && } else if (opt == 0x02 &&
opts[c + 1] == 0x04) { opts[c + 1] == 0x04) {
/* An MSS option with the right option length. */ /* An MSS option with the right option length. */
mss = (opts[c + 2] << 8) | opts[c + 3]; mss = (opts[c + 2] << 8) | opts[c + 3];
@ -1139,7 +1139,7 @@ tcp_parseopt(struct tcp_pcb *pcb)
/* And we are done processing options. */ /* And we are done processing options. */
break; break;
} else { } else {
if(opts[c + 1] == 0) { if (opts[c + 1] == 0) {
/* If the length field is zero, the options are malformed /* If the length field is zero, the options are malformed
and we don't process them further. */ and we don't process them further. */
break; break;

View File

@ -79,11 +79,11 @@ err_t
tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t copy) tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t copy)
{ {
DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, arg=%p, len=%u, copy=%d)\n", (void *)pcb, arg, len, copy)); DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_write(pcb=%p, arg=%p, len=%u, copy=%d)\n", (void *)pcb, arg, len, copy));
if(pcb->state == SYN_SENT || if (pcb->state == SYN_SENT ||
pcb->state == SYN_RCVD || pcb->state == SYN_RCVD ||
pcb->state == ESTABLISHED || pcb->state == ESTABLISHED ||
pcb->state == CLOSE_WAIT) { pcb->state == CLOSE_WAIT) {
if(len > 0) { if (len > 0) {
return tcp_enqueue(pcb, (void *)arg, len, 0, copy, NULL, 0); return tcp_enqueue(pcb, (void *)arg, len, 0, copy, NULL, 0);
} }
return ERR_OK; return ERR_OK;
@ -109,7 +109,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
left = len; left = len;
ptr = arg; ptr = arg;
/* fail on too much data */ /* fail on too much data */
if(len > pcb->snd_buf) { if (len > pcb->snd_buf) {
DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too much data (len=%d > snd_buf=%d)\n", len, pcb->snd_buf)); DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too much data (len=%d > snd_buf=%d)\n", len, pcb->snd_buf));
return ERR_MEM; return ERR_MEM;
} }
@ -124,12 +124,12 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Check if the queue length exceeds the configured maximum queue /* Check if the queue length exceeds the configured maximum queue
length. If so, we return an error. */ length. If so, we return an error. */
queuelen = pcb->snd_queuelen; queuelen = pcb->snd_queuelen;
if(queuelen >= TCP_SND_QUEUELEN) { if (queuelen >= TCP_SND_QUEUELEN) {
DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too long queue %d (max %d)\n", queuelen, TCP_SND_QUEUELEN)); DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too long queue %d (max %d)\n", queuelen, TCP_SND_QUEUELEN));
goto memerr; goto memerr;
} }
if(pcb->snd_queuelen != 0) { if (pcb->snd_queuelen != 0) {
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL || LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL); pcb->unsent != NULL);
} }
@ -139,7 +139,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* First, break up the data into segments and tuck them together in /* First, break up the data into segments and tuck them together in
the local "queue" variable. */ the local "queue" variable. */
while(queue == NULL || left > 0) { while (queue == NULL || left > 0) {
/* The segment length should be the MSS if the data to be enqueued /* The segment length should be the MSS if the data to be enqueued
is larger than the MSS. */ is larger than the MSS. */
@ -147,14 +147,14 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Allocate memory for tcp_seg, and fill in fields. */ /* Allocate memory for tcp_seg, and fill in fields. */
seg = memp_malloc(MEMP_TCP_SEG); seg = memp_malloc(MEMP_TCP_SEG);
if(seg == NULL) { if (seg == NULL) {
DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for tcp_seg\n")); DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for tcp_seg\n"));
goto memerr; goto memerr;
} }
seg->next = NULL; seg->next = NULL;
seg->p = NULL; seg->p = NULL;
if(queue == NULL) { if (queue == NULL) {
queue = seg; queue = seg;
} }
else { else {
@ -168,19 +168,19 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
ROM or other static memory, and need not be copied. If ROM or other static memory, and need not be copied. If
optdata is != NULL, we have options instead of data. */ optdata is != NULL, we have options instead of data. */
if (optdata != NULL) { if (optdata != NULL) {
if((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) { if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, optlen, PBUF_RAM)) == NULL) {
goto memerr; goto memerr;
} }
++queuelen; ++queuelen;
seg->dataptr = seg->p->payload; seg->dataptr = seg->p->payload;
} }
else if (copy) { else if (copy) {
if((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_RAM)) == NULL) { if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_RAM)) == NULL) {
DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue : could not allocate memory for pbuf copy size %u\n", seglen)); DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue : could not allocate memory for pbuf copy size %u\n", seglen));
goto memerr; goto memerr;
} }
++queuelen; ++queuelen;
if(arg != NULL) { if (arg != NULL) {
memcpy(seg->p->payload, ptr, seglen); memcpy(seg->p->payload, ptr, seglen);
} }
seg->dataptr = seg->p->payload; seg->dataptr = seg->p->payload;
@ -193,7 +193,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
* link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM * link (as it has to be ACKed by the remote party) we can safely use PBUF_ROM
* instead of PBUF_REF here. * instead of PBUF_REF here.
*/ */
if((p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_ROM)) == NULL) { if ((p = pbuf_alloc(PBUF_TRANSPORT, seglen, PBUF_ROM)) == NULL) {
DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n")); DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: could not allocate memory for zero-copy pbuf\n"));
goto memerr; goto memerr;
} }
@ -202,7 +202,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
seg->dataptr = ptr; seg->dataptr = ptr;
/* Second, allocate a pbuf for the headers. */ /* Second, allocate a pbuf for the headers. */
if((seg->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM)) == NULL) { if ((seg->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_RAM)) == NULL) {
/* If allocation fails, we have to deallocate the data pbuf as /* If allocation fails, we have to deallocate the data pbuf as
well. */ well. */
pbuf_free(p); pbuf_free(p);
@ -218,18 +218,18 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Now that there are more segments queued, we check again if the /* Now that there are more segments queued, we check again if the
length of the queue exceeds the configured maximum. */ length of the queue exceeds the configured maximum. */
if(queuelen > TCP_SND_QUEUELEN) { if (queuelen > TCP_SND_QUEUELEN) {
DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: queue too long %d (%d)\n", queuelen, TCP_SND_QUEUELEN)); DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: queue too long %d (%d)\n", queuelen, TCP_SND_QUEUELEN));
goto memerr; goto memerr;
} }
seg->len = seglen; seg->len = seglen;
/* if((flags & TCP_SYN) || (flags & TCP_FIN)) { /* if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
++seg->len; ++seg->len;
}*/ }*/
/* Build TCP header. */ /* Build TCP header. */
if(pbuf_header(seg->p, TCP_HLEN)) { if (pbuf_header(seg->p, TCP_HLEN)) {
DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n")); DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_enqueue: no room for TCP header in pbuf.\n"));
@ -247,7 +247,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* don't fill in tcphdr->ackno and tcphdr->wnd until later */ /* don't fill in tcphdr->ackno and tcphdr->wnd until later */
/* Copy the options into the header, if they are present. */ /* Copy the options into the header, if they are present. */
if(optdata == NULL) { if (optdata == NULL) {
TCPH_OFFSET_SET(seg->tcphdr, 5 << 4); TCPH_OFFSET_SET(seg->tcphdr, 5 << 4);
} }
else { else {
@ -271,7 +271,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Now that the data to be enqueued has been broken up into TCP /* Now that the data to be enqueued has been broken up into TCP
segments in the queue variable, we add them to the end of the segments in the queue variable, we add them to the end of the
pcb->unsent queue. */ pcb->unsent queue. */
if(pcb->unsent == NULL) { if (pcb->unsent == NULL) {
useg = NULL; useg = NULL;
} }
else { else {
@ -280,7 +280,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* If there is room in the last pbuf on the unsent queue, /* If there is room in the last pbuf on the unsent queue,
chain the first pbuf on the queue together with that. */ chain the first pbuf on the queue together with that. */
if(useg != NULL && if (useg != NULL &&
TCP_TCPLEN(useg) != 0 && TCP_TCPLEN(useg) != 0 &&
!(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) && !(TCPH_FLAGS(useg->tcphdr) & (TCP_SYN | TCP_FIN)) &&
!(flags & (TCP_SYN | TCP_FIN)) && !(flags & (TCP_SYN | TCP_FIN)) &&
@ -296,13 +296,13 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
useg->next = queue->next; useg->next = queue->next;
DEBUGF(TCP_OUTPUT_DEBUG | DBG_TRACE | DBG_STATE, ("tcp_enqueue: chaining, new len %u\n", useg->len)); DEBUGF(TCP_OUTPUT_DEBUG | DBG_TRACE | DBG_STATE, ("tcp_enqueue: chaining, new len %u\n", useg->len));
if(seg == queue) { if (seg == queue) {
seg = NULL; seg = NULL;
} }
memp_free(MEMP_TCP_SEG, queue); memp_free(MEMP_TCP_SEG, queue);
} }
else { else {
if(useg == NULL) { if (useg == NULL) {
pcb->unsent = queue; pcb->unsent = queue;
} }
@ -310,14 +310,14 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
useg->next = queue; useg->next = queue;
} }
} }
if((flags & TCP_SYN) || (flags & TCP_FIN)) { if ((flags & TCP_SYN) || (flags & TCP_FIN)) {
++len; ++len;
} }
pcb->snd_lbb += len; pcb->snd_lbb += len;
pcb->snd_buf -= len; pcb->snd_buf -= len;
pcb->snd_queuelen = queuelen; pcb->snd_queuelen = queuelen;
DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %d (after enqueued)\n", pcb->snd_queuelen)); DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %d (after enqueued)\n", pcb->snd_queuelen));
if(pcb->snd_queuelen != 0) { if (pcb->snd_queuelen != 0) {
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL || LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL); pcb->unsent != NULL);
@ -325,7 +325,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
/* Set the PSH flag in the last segment that we enqueued, but only /* Set the PSH flag in the last segment that we enqueued, but only
if the segment has data (indicated by seglen > 0). */ if the segment has data (indicated by seglen > 0). */
if(seg != NULL && seglen > 0 && seg->tcphdr != NULL) { if (seg != NULL && seglen > 0 && seg->tcphdr != NULL) {
TCPH_FLAGS_SET(seg->tcphdr, TCPH_FLAGS(seg->tcphdr) | TCP_PSH); TCPH_FLAGS_SET(seg->tcphdr, TCPH_FLAGS(seg->tcphdr) | TCP_PSH);
} }
@ -335,10 +335,10 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
++lwip_stats.tcp.memerr; ++lwip_stats.tcp.memerr;
#endif /* TCP_STATS */ #endif /* TCP_STATS */
if(queue != NULL) { if (queue != NULL) {
tcp_segs_free(queue); tcp_segs_free(queue);
} }
if(pcb->snd_queuelen != 0) { if (pcb->snd_queuelen != 0) {
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL || LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL); pcb->unsent != NULL);
@ -363,7 +363,7 @@ tcp_output(struct tcp_pcb *pcb)
code. If so, we do not output anything. Instead, we rely on the code. If so, we do not output anything. Instead, we rely on the
input processing code to call us when input processing is done input processing code to call us when input processing is done
with. */ with. */
if(tcp_input_pcb == pcb) { if (tcp_input_pcb == pcb) {
return ERR_OK; return ERR_OK;
} }
@ -378,12 +378,12 @@ tcp_output(struct tcp_pcb *pcb)
sent (either because the ->unsent queue is empty or because the sent (either because the ->unsent queue is empty or because the
window doesn't allow it) we'll have to construct an empty ACK window doesn't allow it) we'll have to construct an empty ACK
segment and send it. */ segment and send it. */
if(pcb->flags & TF_ACK_NOW && if (pcb->flags & TF_ACK_NOW &&
(seg == NULL || (seg == NULL ||
ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) { ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) {
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM); p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
if(p == NULL) { if (p == NULL) {
DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n")); DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
return ERR_BUF; return ERR_BUF;
} }
@ -411,12 +411,12 @@ tcp_output(struct tcp_pcb *pcb)
} }
#if TCP_OUTPUT_DEBUG #if TCP_OUTPUT_DEBUG
if(seg == NULL) { if (seg == NULL) {
DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", pcb->unsent)); DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: nothing to send (%p)\n", pcb->unsent));
} }
#endif /* TCP_OUTPUT_DEBUG */ #endif /* TCP_OUTPUT_DEBUG */
#if TCP_CWND_DEBUG #if TCP_CWND_DEBUG
if(seg == NULL) { if (seg == NULL) {
DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %lu, cwnd %lu, wnd %lu, seg == NULL, ack %lu\n", DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %lu, cwnd %lu, wnd %lu, seg == NULL, ack %lu\n",
pcb->snd_wnd, pcb->cwnd, wnd, pcb->snd_wnd, pcb->cwnd, wnd,
pcb->lastack)); pcb->lastack));
@ -428,7 +428,7 @@ tcp_output(struct tcp_pcb *pcb)
} }
#endif /* TCP_CWND_DEBUG */ #endif /* TCP_CWND_DEBUG */
while(seg != NULL && while (seg != NULL &&
ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) {
#if TCP_CWND_DEBUG #if TCP_CWND_DEBUG
DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %lu, cwnd %lu, wnd %lu, effwnd %lu, seq %lu, ack %lu, i%d\n", DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %lu, cwnd %lu, wnd %lu, effwnd %lu, seq %lu, ack %lu, i%d\n",
@ -441,20 +441,20 @@ tcp_output(struct tcp_pcb *pcb)
pcb->unsent = seg->next; pcb->unsent = seg->next;
if(pcb->state != SYN_SENT) { if (pcb->state != SYN_SENT) {
TCPH_FLAGS_SET(seg->tcphdr, TCPH_FLAGS(seg->tcphdr) | TCP_ACK); TCPH_FLAGS_SET(seg->tcphdr, TCPH_FLAGS(seg->tcphdr) | TCP_ACK);
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
} }
tcp_output_segment(seg, pcb); tcp_output_segment(seg, pcb);
pcb->snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg); pcb->snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg);
if(TCP_SEQ_LT(pcb->snd_max, pcb->snd_nxt)) { if (TCP_SEQ_LT(pcb->snd_max, pcb->snd_nxt)) {
pcb->snd_max = pcb->snd_nxt; pcb->snd_max = pcb->snd_nxt;
} }
/* put segment on unacknowledged list if length > 0 */ /* put segment on unacknowledged list if length > 0 */
if(TCP_TCPLEN(seg) > 0) { if (TCP_TCPLEN(seg) > 0) {
seg->next = NULL; seg->next = NULL;
if(pcb->unacked == NULL) { if (pcb->unacked == NULL) {
pcb->unacked = seg; pcb->unacked = seg;
@ -481,7 +481,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
seg->tcphdr->ackno = htonl(pcb->rcv_nxt); seg->tcphdr->ackno = htonl(pcb->rcv_nxt);
/* silly window avoidance */ /* silly window avoidance */
if(pcb->rcv_wnd < pcb->mss) { if (pcb->rcv_wnd < pcb->mss) {
seg->tcphdr->wnd = 0; seg->tcphdr->wnd = 0;
} else { } else {
/* advertise our receive window size in this TCP segment */ /* advertise our receive window size in this TCP segment */
@ -490,9 +490,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
/* If we don't have a local IP address, we get one by /* If we don't have a local IP address, we get one by
calling ip_route(). */ calling ip_route(). */
if(ip_addr_isany(&(pcb->local_ip))) { if (ip_addr_isany(&(pcb->local_ip))) {
netif = ip_route(&(pcb->remote_ip)); netif = ip_route(&(pcb->remote_ip));
if(netif == NULL) { if (netif == NULL) {
return; return;
} }
ip_addr_set(&(pcb->local_ip), &(netif->ip_addr)); ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
@ -500,7 +500,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
pcb->rtime = 0; pcb->rtime = 0;
if(pcb->rttest == 0) { if (pcb->rttest == 0) {
pcb->rttest = tcp_ticks; pcb->rttest = tcp_ticks;
pcb->rtseq = ntohl(seg->tcphdr->seqno); pcb->rtseq = ntohl(seg->tcphdr->seqno);
@ -538,7 +538,7 @@ tcp_rst(u32_t seqno, u32_t ackno,
struct pbuf *p; struct pbuf *p;
struct tcp_hdr *tcphdr; struct tcp_hdr *tcphdr;
p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM); p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
if(p == NULL) { if (p == NULL) {
DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n")); DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n"));
return; return;
} }
@ -570,7 +570,7 @@ tcp_rexmit(struct tcp_pcb *pcb)
{ {
struct tcp_seg *seg; struct tcp_seg *seg;
if(pcb->unacked == NULL) { if (pcb->unacked == NULL) {
return; return;
} }

View File

@ -102,7 +102,7 @@ udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
dest = ntohs(udphdr->dest); dest = ntohs(udphdr->dest);
pcb = pcb_cache; pcb = pcb_cache;
if(pcb != NULL && if (pcb != NULL &&
pcb->remote_port == src && pcb->remote_port == src &&
pcb->local_port == dest && pcb->local_port == dest &&
(ip_addr_isany(&pcb->remote_ip) || (ip_addr_isany(&pcb->remote_ip) ||
@ -113,7 +113,7 @@ udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
} }
else { else {
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->remote_port == src && if (pcb->remote_port == src &&
pcb->local_port == dest && pcb->local_port == dest &&
(ip_addr_isany(&pcb->remote_ip) || (ip_addr_isany(&pcb->remote_ip) ||
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
@ -124,9 +124,9 @@ udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
} }
} }
if(pcb == NULL) { if (pcb == NULL) {
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
if(pcb->remote_port == 0 && if (pcb->remote_port == 0 &&
pcb->local_port == dest && pcb->local_port == dest &&
(ip_addr_isany(&pcb->remote_ip) || (ip_addr_isany(&pcb->remote_ip) ||
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) && ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src))) &&
@ -140,7 +140,7 @@ udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
PERF_STOP("udp_lookup"); PERF_STOP("udp_lookup");
if(pcb != NULL) { if (pcb != NULL) {
return 1; return 1;
} }
else { else {
@ -214,7 +214,7 @@ udp_input(struct pbuf *p, struct netif *inp)
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port)); ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));
/* PCB remote port matches UDP source port? */ /* PCB remote port matches UDP source port? */
if((pcb->remote_port == src) && if ((pcb->remote_port == src) &&
/* PCB local port matches UDP destination port? */ /* PCB local port matches UDP destination port? */
(pcb->local_port == dest) && (pcb->local_port == dest) &&
/* accepting from any remote (source) IP address? or... */ /* accepting from any remote (source) IP address? or... */
@ -239,7 +239,7 @@ udp_input(struct pbuf *p, struct netif *inp)
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip), ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port)); ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));
/* unconnected? */ /* unconnected? */
if(((pcb->flags & UDP_FLAGS_CONNECTED) == 0) && if (((pcb->flags & UDP_FLAGS_CONNECTED) == 0) &&
/* destination port matches? */ /* destination port matches? */
(pcb->local_port == dest) && (pcb->local_port == dest) &&
/* not bound to a specific (local) interface address? or... */ /* not bound to a specific (local) interface address? or... */
@ -252,17 +252,17 @@ udp_input(struct pbuf *p, struct netif *inp)
} }
/* Check checksum if this is a match or if it was directed at us. */ /* Check checksum if this is a match or if it was directed at us. */
if(pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest)) if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &iphdr->dest))
{ {
DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: calculating checksum\n")); DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: calculating checksum\n"));
pbuf_header(p, UDP_HLEN); pbuf_header(p, UDP_HLEN);
#ifdef IPv6 #ifdef IPv6
if(iphdr->nexthdr == IP_PROTO_UDPLITE) { if (iphdr->nexthdr == IP_PROTO_UDPLITE) {
#else #else
if(IPH_PROTO(iphdr) == IP_PROTO_UDPLITE) { if (IPH_PROTO(iphdr) == IP_PROTO_UDPLITE) {
#endif /* IPv4 */ #endif /* IPv4 */
/* Do the UDP Lite checksum */ /* Do the UDP Lite checksum */
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest), (struct ip_addr *)&(iphdr->dest),
IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) { IP_PROTO_UDPLITE, ntohs(udphdr->len)) != 0) {
DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP Lite datagram discarded due to failing checksum\n")); DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP Lite datagram discarded due to failing checksum\n"));
@ -275,8 +275,8 @@ udp_input(struct pbuf *p, struct netif *inp)
goto end; goto end;
} }
} else { } else {
if(udphdr->chksum != 0) { if (udphdr->chksum != 0) {
if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest), (struct ip_addr *)&(iphdr->dest),
IP_PROTO_UDP, p->tot_len) != 0) { IP_PROTO_UDP, p->tot_len) != 0) {
DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP datagram discarded due to failing checksum\n")); DEBUGF(UDP_DEBUG | 2, ("udp_input: UDP datagram discarded due to failing checksum\n"));
@ -292,7 +292,7 @@ udp_input(struct pbuf *p, struct netif *inp)
} }
} }
pbuf_header(p, -UDP_HLEN); pbuf_header(p, -UDP_HLEN);
if(pcb != NULL) { if (pcb != NULL) {
snmp_inc_udpindatagrams(); snmp_inc_udpindatagrams();
pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src); pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), src);
} else { } else {
@ -301,7 +301,7 @@ udp_input(struct pbuf *p, struct netif *inp)
/* No match was found, send ICMP destination port unreachable unless /* No match was found, send ICMP destination port unreachable unless
destination address was broadcast/multicast. */ destination address was broadcast/multicast. */
if(!ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) && if (!ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) &&
!ip_addr_ismulticast(&iphdr->dest)) { !ip_addr_ismulticast(&iphdr->dest)) {
/* adjust pbuf pointer */ /* adjust pbuf pointer */
@ -409,9 +409,9 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
udphdr->chksum = inet_chksum_pseudo(q, src_ip, &(pcb->remote_ip), udphdr->chksum = inet_chksum_pseudo(q, src_ip, &(pcb->remote_ip),
IP_PROTO_UDP, pcb->chksum_len); IP_PROTO_UDP, pcb->chksum_len);
/* chksum zero must become 0xffff, as zero means 'no checksum' */ /* chksum zero must become 0xffff, as zero means 'no checksum' */
if(udphdr->chksum == 0x0000) udphdr->chksum = 0xffff; if (udphdr->chksum == 0x0000) udphdr->chksum = 0xffff;
/* output to IP */ /* output to IP */
err = ip_output_if(q, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDPLITE, netif); err = ip_output_if (q, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDPLITE, netif);
snmp_inc_udpoutdatagrams(); snmp_inc_udpoutdatagrams();
} else { } else {
DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %u\n", q->tot_len)); DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %u\n", q->tot_len));
@ -424,9 +424,9 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
} }
DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04x\n", udphdr->chksum)); DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04x\n", udphdr->chksum));
snmp_inc_udpoutdatagrams(); snmp_inc_udpoutdatagrams();
DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if(,,,,IP_PROTO_UDP,)\n")); DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n"));
/* output to IP */ /* output to IP */
err = ip_output_if(q, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDP, netif); err = ip_output_if (q, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDP, netif);
} }
/* did we chain a header earlier? */ /* did we chain a header earlier? */
@ -544,9 +544,9 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{ {
struct udp_pcb *ipcb; struct udp_pcb *ipcb;
if(pcb->local_port == 0) { if (pcb->local_port == 0) {
err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port); err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
if(err != ERR_OK) if (err != ERR_OK)
return err; return err;
} }
@ -556,10 +556,10 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
#if 0 #if 0
pcb->flags |= UDP_FLAGS_CONNECTED; pcb->flags |= UDP_FLAGS_CONNECTED;
/* Nail down local IP for netconn_addr()/getsockname() */ /* Nail down local IP for netconn_addr()/getsockname() */
if(ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) { if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
struct netif *netif; struct netif *netif;
if((netif = ip_route(&(pcb->remote_ip))) == NULL) { if ((netif = ip_route(&(pcb->remote_ip))) == NULL) {
DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr)); DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
#ifdef UDP_STATS #ifdef UDP_STATS
++lwip_stats.udp.rterr; ++lwip_stats.udp.rterr;
@ -570,7 +570,7 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
is used to route output packets to the remote address. However, we is used to route output packets to the remote address. However, we
might want to accept incoming packets on any interface! */ might want to accept incoming packets on any interface! */
pcb->local_ip = netif->ip_addr; pcb->local_ip = netif->ip_addr;
} else if(ip_addr_isany(&pcb->remote_ip)) { } else if (ip_addr_isany(&pcb->remote_ip)) {
pcb->local_ip.addr = 0; pcb->local_ip.addr = 0;
} }
#endif #endif
@ -582,7 +582,7 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
/* Insert UDP PCB into the list of active UDP PCBs. */ /* Insert UDP PCB into the list of active UDP PCBs. */
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) { for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
if(pcb == ipcb) { if (pcb == ipcb) {
/* already on the list, just return */ /* already on the list, just return */
return ERR_OK; return ERR_OK;
} }
@ -628,7 +628,7 @@ udp_remove(struct udp_pcb *pcb)
/* pcb not 1st in list */ /* pcb not 1st in list */
} else for(pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) { } else for(pcb2 = udp_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
/* find pcb in udp_pcbs list */ /* find pcb in udp_pcbs list */
if(pcb2->next != NULL && pcb2->next == pcb) { if (pcb2->next != NULL && pcb2->next == pcb) {
/* remove pcb from list */ /* remove pcb from list */
pcb2->next = pcb->next; pcb2->next = pcb->next;
} }
@ -648,7 +648,7 @@ udp_new(void) {
struct udp_pcb *pcb; struct udp_pcb *pcb;
pcb = memp_malloc(MEMP_UDP_PCB); pcb = memp_malloc(MEMP_UDP_PCB);
/* could allocate UDP PCB? */ /* could allocate UDP PCB? */
if(pcb != NULL) { if (pcb != NULL) {
/* initialize PCB to all zeroes */ /* initialize PCB to all zeroes */
memset(pcb, 0, sizeof(struct udp_pcb)); memset(pcb, 0, sizeof(struct udp_pcb));
} }

View File

@ -2,6 +2,10 @@
* @file * @file
* Address Resolution Protocol module for IP over Ethernet * Address Resolution Protocol module for IP over Ethernet
* *
* Functionally, ARP is divided into two parts. The first maps an IP address
* to a physical address when sending a packet, and the second part answers
* requests from other machines.
*
*/ */
/* /*
@ -147,10 +151,10 @@ etharp_tmr(void)
DEBUGF(ETHARP_DEBUG, ("etharp_timer\n")); DEBUGF(ETHARP_DEBUG, ("etharp_timer\n"));
/* remove expired entries from the ARP table */ /* remove expired entries from the ARP table */
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for (i = 0; i < ARP_TABLE_SIZE; ++i) {
arp_table[i].ctime++; arp_table[i].ctime++;
if((arp_table[i].state == ETHARP_STATE_STABLE) && if ((arp_table[i].state == ETHARP_STATE_STABLE) &&
(arp_table[i].ctime >= ARP_MAXAGE)) { (arp_table[i].ctime >= ARP_MAXAGE)) {
DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired stable entry %u.\n", i)); DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired stable entry %u.\n", i));
arp_table[i].state = ETHARP_STATE_EMPTY; arp_table[i].state = ETHARP_STATE_EMPTY;
#if ARP_QUEUEING #if ARP_QUEUEING
@ -158,7 +162,7 @@ etharp_tmr(void)
pbuf_free(arp_table[i].p); pbuf_free(arp_table[i].p);
arp_table[i].p = NULL; arp_table[i].p = NULL;
#endif #endif
} else if((arp_table[i].state == ETHARP_STATE_PENDING) && } else if ((arp_table[i].state == ETHARP_STATE_PENDING) &&
(arp_table[i].ctime >= ARP_MAXPENDING)) { (arp_table[i].ctime >= ARP_MAXPENDING)) {
arp_table[i].state = ETHARP_STATE_EMPTY; arp_table[i].state = ETHARP_STATE_EMPTY;
#if ARP_QUEUEING #if ARP_QUEUEING
@ -186,8 +190,8 @@ find_arp_entry(void)
u8_t i, j, maxtime; u8_t i, j, maxtime;
/* Try to find an unused entry in the ARP table. */ /* Try to find an unused entry in the ARP table. */
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for (i = 0; i < ARP_TABLE_SIZE; ++i) {
if(arp_table[i].state == ETHARP_STATE_EMPTY) { if (arp_table[i].state == ETHARP_STATE_EMPTY) {
DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found empty entry %u\n", i)); DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found empty entry %u\n", i));
break; break;
} }
@ -195,12 +199,12 @@ find_arp_entry(void)
/* If no unused entry is found, we try to find the oldest entry and /* If no unused entry is found, we try to find the oldest entry and
throw it away. If all entries are new and have 0 ctime drop one */ throw it away. If all entries are new and have 0 ctime drop one */
if(i == ARP_TABLE_SIZE) { if (i == ARP_TABLE_SIZE) {
maxtime = 0; maxtime = 0;
j = ARP_TABLE_SIZE; j = ARP_TABLE_SIZE;
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for (i = 0; i < ARP_TABLE_SIZE; ++i) {
/* remember entry with oldest stable entry in j*/ /* remember entry with oldest stable entry in j*/
if((arp_table[i].state == ETHARP_STATE_STABLE) && if ((arp_table[i].state == ETHARP_STATE_STABLE) &&
#if ARP_QUEUEING /* do not want to re-use an entry with queued packets */ #if ARP_QUEUEING /* do not want to re-use an entry with queued packets */
(arp_table[i].p == NULL) && (arp_table[i].p == NULL) &&
#endif #endif
@ -209,7 +213,11 @@ find_arp_entry(void)
j = i; j = i;
} }
} }
DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found oldest stable entry %u\n", j)); if (j != ARP_TABLE_SIZE) {
DEBUGF(ETHARP_DEBUG, ("find_arp_entry: found oldest stable entry %u\n", j));
} else {
DEBUGF(ETHARP_DEBUG, ("find_arp_entry: no replacable entry could be found\n", j));
}
i = j; i = j;
} }
DEBUGF(ETHARP_DEBUG, ("find_arp_entry: returning %u, state %u\n", i, arp_table[i].state)); DEBUGF(ETHARP_DEBUG, ("find_arp_entry: returning %u, state %u\n", i, arp_table[i].state));
@ -234,11 +242,8 @@ static struct pbuf *
update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags) update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags)
{ {
u8_t i, k; u8_t i, k;
#if ARP_QUEUEING
struct pbuf *p;
struct eth_hdr *ethhdr;
#endif
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("update_arp_entry()\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("update_arp_entry()\n"));
LWIP_ASSERT("netif->hwaddr_len != 0", netif->hwaddr_len != 0);
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: %u.%u.%u.%u - %02x:%02x:%02x:%02x:%02x:%02x\n", ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr), DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: %u.%u.%u.%u - %02x:%02x:%02x:%02x:%02x:%02x\n", ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr),
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2], ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5])); ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2], ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
/* do not update for 0.0.0.0 addresses */ /* do not update for 0.0.0.0 addresses */
@ -249,34 +254,39 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
/* Walk through the ARP mapping table and try to find an entry to /* Walk through the ARP mapping table and try to find an entry to
update. If none is found, the IP -> MAC address mapping is update. If none is found, the IP -> MAC address mapping is
inserted in the ARP table. */ inserted in the ARP table. */
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for (i = 0; i < ARP_TABLE_SIZE; ++i) {
/* Check if the source IP address of the incoming packet matches /* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */ the IP address in this ARP table entry. */
if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { if (ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
/* pending entry? */ /* pending entry? */
if(arp_table[i].state == ETHARP_STATE_PENDING) { if (arp_table[i].state == ETHARP_STATE_PENDING) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: pending entry %u goes stable\n", i)); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: pending entry %u goes stable\n", i));
/* A pending entry was found, mark it stable */ /* A pending entry was found, mark it stable */
arp_table[i].state = ETHARP_STATE_STABLE; arp_table[i].state = ETHARP_STATE_STABLE;
/* fall-through to next if */ /* fall-through to next if */
} }
/* stable entry? (possible just marked to become stable) */ /* stable entry? (possible just marked to become stable) */
if(arp_table[i].state == ETHARP_STATE_STABLE) { if (arp_table[i].state == ETHARP_STATE_STABLE) {
#if ARP_QUEUEING
struct pbuf *p;
struct eth_hdr *ethhdr;
#endif
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: updating stable entry %u\n", i)); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: updating stable entry %u\n", i));
/* An old entry found, update this and return. */ /* An old entry found, update this and return. */
for(k = 0; k < netif->hwaddr_len; ++k) { for (k = 0; k < netif->hwaddr_len; ++k) {
arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
} }
/* reset time stamp */ /* reset time stamp */
arp_table[i].ctime = 0; arp_table[i].ctime = 0;
#if ARP_QUEUEING #if ARP_QUEUEING
p = arp_table[i].p;
/* queued packet present? */ /* queued packet present? */
if((p = arp_table[i].p) != NULL) { if (p != NULL) {
/* Null out attached buffer immediately */ /* NULL attached buffer immediately */
arp_table[i].p = NULL; arp_table[i].p = NULL;
/* fill-in Ethernet header */ /* fill-in Ethernet header */
ethhdr = p->payload; ethhdr = p->payload;
for(k = 0; k < netif->hwaddr_len; ++k) { for (k = 0; k < netif->hwaddr_len; ++k) {
ethhdr->dest.addr[k] = ethaddr->addr[k]; ethhdr->dest.addr[k] = ethaddr->addr[k];
} }
ethhdr->type = htons(ETHTYPE_IP); ethhdr->type = htons(ETHTYPE_IP);
@ -302,7 +312,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: adding entry to table\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: adding entry to table\n"));
/* find an empty or old entry. */ /* find an empty or old entry. */
i = find_arp_entry(); i = find_arp_entry();
if(i == ARP_TABLE_SIZE) { if (i == ARP_TABLE_SIZE) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: no available entry found\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: no available entry found\n"));
return NULL; return NULL;
} }
@ -320,7 +330,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
/* set IP address */ /* set IP address */
ip_addr_set(&arp_table[i].ipaddr, ipaddr); ip_addr_set(&arp_table[i].ipaddr, ipaddr);
/* set Ethernet hardware address */ /* set Ethernet hardware address */
for(k = 0; k < netif->hwaddr_len; ++k) { for (k = 0; k < netif->hwaddr_len; ++k) {
arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
} }
/* reset time-stamp */ /* reset time-stamp */
@ -363,7 +373,7 @@ etharp_ip_input(struct netif *netif, struct pbuf *p)
incoming IP packet comes from a host on the local network. */ incoming IP packet comes from a host on the local network. */
hdr = p->payload; hdr = p->payload;
/* source is on local network? */ /* source is on local network? */
if(!ip_addr_maskcmp(&(hdr->ip.src), &(netif->ip_addr), &(netif->netmask))) { if (!ip_addr_maskcmp(&(hdr->ip.src), &(netif->ip_addr), &(netif->netmask))) {
/* do nothing */ /* do nothing */
return NULL; return NULL;
} }
@ -396,7 +406,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
u8_t i; u8_t i;
/* drop short ARP packets */ /* drop short ARP packets */
if(p->tot_len < sizeof(struct etharp_hdr)) { if (p->tot_len < sizeof(struct etharp_hdr)) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 1, ("etharp_arp_input: packet too short (%d/%d)\n", p->tot_len, sizeof(struct etharp_hdr))); DEBUGF(ETHARP_DEBUG | DBG_TRACE | 1, ("etharp_arp_input: packet too short (%d/%d)\n", p->tot_len, sizeof(struct etharp_hdr)));
pbuf_free(p); pbuf_free(p);
return NULL; return NULL;
@ -404,16 +414,16 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
hdr = p->payload; hdr = p->payload;
switch(htons(hdr->opcode)) { switch (htons(hdr->opcode)) {
/* ARP request? */ /* ARP request? */
case ARP_REQUEST: case ARP_REQUEST:
/* ARP request. If it asked for our address, we send out a /* ARP request. If it asked for our address, we send out a
reply. In any case, we time-stamp any existing ARP entry, reply. In any case, we time-stamp any existing ARP entry,
and possiby send out an IP packet that was queued on it. */ and possiby send out an IP packet that was queued on it. */
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP request\n")); DEBUGF (ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP request\n"));
/* we are not configured? */ /* we are not configured? */
if(netif->ip_addr.addr == 0) { if (netif->ip_addr.addr == 0) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n"));
pbuf_free(p); pbuf_free(p);
return NULL; return NULL;
@ -421,7 +431,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
/* update the ARP cache */ /* update the ARP cache */
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0); update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);
/* ARP request for our address? */ /* ARP request for our address? */
if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { if (ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: replying to ARP request for our IP address\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: replying to ARP request for our IP address\n"));
/* re-use pbuf to send ARP reply */ /* re-use pbuf to send ARP reply */
@ -458,7 +468,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
dhcp_arp_reply(netif, &hdr->sipaddr); dhcp_arp_reply(netif, &hdr->sipaddr);
#endif #endif
/* ARP reply directed to us? */ /* ARP reply directed to us? */
if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { if (ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply is for us\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply is for us\n"));
/* update_the ARP cache, ask to insert */ /* update_the ARP cache, ask to insert */
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG); update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG);
@ -514,7 +524,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
u8_t i; u8_t i;
/* Make room for Ethernet header. */ /* Make room for Ethernet header. */
if(pbuf_header(q, sizeof(struct eth_hdr)) != 0) { if (pbuf_header(q, sizeof(struct eth_hdr)) != 0) {
/* The pbuf_header() call shouldn't fail, and we'll just bail /* The pbuf_header() call shouldn't fail, and we'll just bail
out if it does.. */ out if it does.. */
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_output: could not allocate room for header.\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_output: could not allocate room for header.\n"));
@ -535,13 +545,13 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
ARP table. */ ARP table. */
/* destination IP address is an IP broadcast address? */ /* destination IP address is an IP broadcast address? */
if(ip_addr_isany(ipaddr) || if (ip_addr_isany(ipaddr) ||
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { ip_addr_isbroadcast(ipaddr, &(netif->netmask))) {
/* broadcast on Ethernet also */ /* broadcast on Ethernet also */
dest = (struct eth_addr *)&ethbroadcast; dest = (struct eth_addr *)&ethbroadcast;
} }
/* destination IP address is an IP multicast address? */ /* destination IP address is an IP multicast address? */
else if(ip_addr_ismulticast(ipaddr)) { else if (ip_addr_ismulticast(ipaddr)) {
/* Hash IP multicast address to MAC address. */ /* Hash IP multicast address to MAC address. */
mcastaddr.addr[0] = 0x01; mcastaddr.addr[0] = 0x01;
mcastaddr.addr[1] = 0x0; mcastaddr.addr[1] = 0x0;
@ -556,7 +566,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
else { else {
/* destination IP network address not on local network? */ /* destination IP network address not on local network? */
/* this occurs if the packet is routed to the default gateway on this interface */ /* this occurs if the packet is routed to the default gateway on this interface */
if(!ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { if (!ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) {
/* gateway available? */ /* gateway available? */
if (netif->gw.addr != 0) if (netif->gw.addr != 0)
{ {
@ -574,7 +584,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
/* Ethernet address for IP destination address is in ARP cache? */ /* Ethernet address for IP destination address is in ARP cache? */
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for(i = 0; i < ARP_TABLE_SIZE; ++i) {
/* match found? */ /* match found? */
if(arp_table[i].state == ETHARP_STATE_STABLE && if (arp_table[i].state == ETHARP_STATE_STABLE &&
ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
dest = &arp_table[i].ethaddr; dest = &arp_table[i].ethaddr;
break; break;
@ -652,16 +662,18 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
srcaddr = (struct eth_addr *)netif->hwaddr; srcaddr = (struct eth_addr *)netif->hwaddr;
/* bail out if this IP address is pending */ /* bail out if this IP address is pending */
for(i = 0; i < ARP_TABLE_SIZE; ++i) { for(i = 0; i < ARP_TABLE_SIZE; ++i) {
if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { if (ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
if (arp_table[i].state == ETHARP_STATE_PENDING) { if (arp_table[i].state == ETHARP_STATE_PENDING) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already pending as entry %u\n", i)); DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already pending as entry %u\n", i));
/* break out of for-loop, user may wish to queue a packet on a stable entry */ /* break out of for-loop, user may wish to queue a packet on a stable entry */
/* TODO: we will issue a new ARP request, which should not occur too often */
/* we might want to run a faster timer on ARP to limit this */
break; break;
} }
else if (arp_table[i].state == ETHARP_STATE_STABLE) { else if (arp_table[i].state == ETHARP_STATE_STABLE) {
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already stable as entry %u\n", i)); DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already stable as entry %u\n", i));
/* user may wish to queue a packet on a stable entry, so we proceed without ARP requesting */ /* user may wish to queue a packet on a stable entry, so we proceed without ARP requesting */
/* TODO: even if the ARP entry is stable, we might do an ARP request anyway in some cases? */ /* TODO: even if the ARP entry is stable, we might do an ARP request anyway */
perform_arp_request = 0; perform_arp_request = 0;
break; break;
} }
@ -677,6 +689,7 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
DEBUGF(ETHARP_DEBUG | 2, ("etharp_query: no more ARP entries available.\n")); DEBUGF(ETHARP_DEBUG | 2, ("etharp_query: no more ARP entries available.\n"));
return ERR_MEM; return ERR_MEM;
} }
/* we will now recycle entry i */
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: created ARP table entry %u.\n", i)); DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: created ARP table entry %u.\n", i));
/* i is available, create ARP entry */ /* i is available, create ARP entry */
ip_addr_set(&arp_table[i].ipaddr, ipaddr); ip_addr_set(&arp_table[i].ipaddr, ipaddr);
@ -701,11 +714,12 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
pbuf_free(arp_table[i].p); pbuf_free(arp_table[i].p);
arp_table[i].p = NULL; arp_table[i].p = NULL;
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dropped packet on ARP queue. Should not occur.\n")); DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dropped packet on ARP queue. Should not occur.\n"));
/* fall-through into next if */
} }
#endif #endif
/* packet can be queued? */ /* packet can be queued? */
if (arp_table[i].p == NULL) { if (arp_table[i].p == NULL) {
/* copy PBUF_REF referenced payloads to PBUF_RAM */ /* copy PBUF_REF referenced payloads into PBUF_RAM */
q = pbuf_take(q); q = pbuf_take(q);
/* remember pbuf to queue, if any */ /* remember pbuf to queue, if any */
arp_table[i].p = q; arp_table[i].p = q;

View File

@ -144,7 +144,7 @@ low_level_input(struct ethernetif *ethernetif)
/* We allocate a pbuf chain of pbufs from the pool. */ /* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if(p != NULL) { if (p != NULL) {
/* We iterate over the pbuf chain until we have read the entire /* We iterate over the pbuf chain until we have read the entire
packet into the pbuf. */ packet into the pbuf. */
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
@ -192,11 +192,11 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
ethernetif = netif->state; ethernetif = netif->state;
/* Make room for Ethernet header. */ /* Make room for Ethernet header. */
if(pbuf_header(p, 14) != 0) { if (pbuf_header(p, 14) != 0) {
/* The pbuf_header() call shouldn't fail, but we allocate an extra /* The pbuf_header() call shouldn't fail, but we allocate an extra
pbuf just in case. */ pbuf just in case. */
q = pbuf_alloc(PBUF_LINK, 14, PBUF_RAM); q = pbuf_alloc(PBUF_LINK, 14, PBUF_RAM);
if(q == NULL) { if (q == NULL) {
#ifdef LINK_STATS #ifdef LINK_STATS
lwip_stats.link.drop++; lwip_stats.link.drop++;
lwip_stats.link.memerr++; lwip_stats.link.memerr++;
@ -212,10 +212,10 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
multicasts are special, all other addresses are looked up in the multicasts are special, all other addresses are looked up in the
ARP table. */ ARP table. */
queryaddr = ipaddr; queryaddr = ipaddr;
if(ip_addr_isany(ipaddr) || if (ip_addr_isany(ipaddr) ||
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { ip_addr_isbroadcast(ipaddr, &(netif->netmask))) {
dest = (struct eth_addr *)&ethbroadcast; dest = (struct eth_addr *)&ethbroadcast;
} else if(ip_addr_ismulticast(ipaddr)) { } else if (ip_addr_ismulticast(ipaddr)) {
/* Hash IP multicast address to MAC address. */ /* Hash IP multicast address to MAC address. */
mcastaddr.addr[0] = 0x01; mcastaddr.addr[0] = 0x01;
mcastaddr.addr[1] = 0x0; mcastaddr.addr[1] = 0x0;
@ -226,7 +226,7 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
dest = &mcastaddr; dest = &mcastaddr;
} else { } else {
if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { if (ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) {
/* Use destination IP address if the destination is on the same /* Use destination IP address if the destination is on the same
subnet as we are. */ subnet as we are. */
queryaddr = ipaddr; queryaddr = ipaddr;
@ -241,9 +241,9 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
/* If the arp_lookup() didn't find an address, we send out an ARP /* If the arp_lookup() didn't find an address, we send out an ARP
query for the IP address. */ query for the IP address. */
if(dest == NULL) { if (dest == NULL) {
q = arp_query(netif, ethernetif->ethaddr, queryaddr); q = arp_query(netif, ethernetif->ethaddr, queryaddr);
if(q != NULL) { if (q != NULL) {
err = low_level_output(ethernetif, q); err = low_level_output(ethernetif, q);
pbuf_free(q); pbuf_free(q);
return err; return err;
@ -289,7 +289,7 @@ ethernetif_input(struct netif *netif)
p = low_level_input(ethernetif); p = low_level_input(ethernetif);
if(p != NULL) { if (p != NULL) {
#ifdef LINK_STATS #ifdef LINK_STATS
lwip_stats.link.recv++; lwip_stats.link.recv++;
@ -297,7 +297,7 @@ ethernetif_input(struct netif *netif)
ethhdr = p->payload; ethhdr = p->payload;
switch(htons(ethhdr->type)) { switch (htons(ethhdr->type)) {
case ETHTYPE_IP: case ETHTYPE_IP:
arp_ip_input(netif, p); arp_ip_input(netif, p);
pbuf_header(p, -14); pbuf_header(p, -14);
@ -305,7 +305,7 @@ ethernetif_input(struct netif *netif)
break; break;
case ETHTYPE_ARP: case ETHTYPE_ARP:
p = arp_arp_input(netif, ethernetif->ethaddr, p); p = arp_arp_input(netif, ethernetif->ethaddr, p);
if(p != NULL) { if (p != NULL) {
low_level_output(ethernetif, p); low_level_output(ethernetif, p);
pbuf_free(p); pbuf_free(p);
} }

View File

@ -53,7 +53,7 @@ loopif_output(struct netif *netif, struct pbuf *p,
#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ #endif /* LWIP_DEBUG && LWIP_TCPDUMP */
r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
if(r != NULL) { if (r != NULL) {
ptr = r->payload; ptr = r->payload;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {

View File

@ -69,7 +69,7 @@ slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
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);
@ -107,11 +107,11 @@ slipif_input( struct netif * netif )
recved = i = 0; recved = i = 0;
c = 0; c = 0;
while(1) { while (1) {
c = sio_recv(netif->state); c = sio_recv(netif->state);
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);
@ -126,7 +126,7 @@ slipif_input( struct netif * netif )
case SLIP_ESC: case SLIP_ESC:
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;
@ -137,28 +137,28 @@ slipif_input( struct netif * netif )
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
if(p == NULL) { if (p == NULL) {
DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n")); 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);
#ifdef LINK_STATS #ifdef LINK_STATS
if(p == NULL) { if (p == NULL) {
++lwip_stats.link.drop; ++lwip_stats.link.drop;
DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n")); DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
} }
#endif /* LINK_STATS */ #endif /* LINK_STATS */
if(q != NULL) { if (q != NULL) {
pbuf_chain(q, p); pbuf_chain(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; p = NULL;
} }
@ -181,7 +181,7 @@ slipif_loop(void *nf)
struct pbuf *p; struct pbuf *p;
struct netif *netif = (struct netif *)nf; struct netif *netif = (struct netif *)nf;
while(1) { while (1) {
p = slipif_input(netif); p = slipif_input(netif);
netif->input(p, netif); netif->input(p, netif);
} }