Add the following features and bugfixes:

Added select() functionality to sockets library.
Support for errno in sockets library.
Byte ordering fixes.
basic lwip_ioctl(), FIONREAD, get/setsockopt() etc. support

- added additional argument to netif_add to pass state pointer so that the
if_init function has access to context information before
the interface is added, without accessing globals.

- added netif_remove()

- to conserve cpu load the tcpip_tcp_timer should only be active
when tcbs that need it exist.

- pass length of available data to callbacks for NETCONN_EVT_RCV events

- added tcpip_link_input(), a hack to allow processing of PPP
packets in tcpip_thread() context. This saves threads and context
switches.

- renamed incompatible ASSERT() macro to LWIP_ASSERT() to avoid name
collision.

- changed a bunch of %d's to %u's in format strings for unsigned values.

- added ip_frag to lwip_stats.

- changed IP_REASS_MAXAGE and IP_REASS_TMO defaults to more realistic
values.

- added sys_timeout_remove() function to cancel timeouts (needed by PPP
amongst other things).

- tolerate NULL returns from sys_arch_timeouts() since some threads might
not need to use or have timeouts.

- added sys_sem_wait_timeout()

- moved mem_malloc() function to end of mem.c to work around tasking
compiler bug.

- automatically bind to local tcp port if 0.

- allow customization of port ranges for automatic local bindings.

- corrected various typos, spelling errors, etc..

Thanks to Marc Boucher for many of these changes.
This commit is contained in:
davidhaas
2003-02-06 22:18:56 +00:00
parent d2e008d4b4
commit dd2fa15e8a
28 changed files with 1599 additions and 300 deletions

View File

@@ -913,8 +913,8 @@ void dhcp_stop(struct dhcp_state *state)
{
struct dhcp_state *list_state = client_list;
DEBUGF(DHCP_DEBUG, ("dhcp_stop()"));
ASSERT("dhcp_stop: state != NULL", state != NULL);
ASSERT("dhcp_stop: state->pcb != NULL", state->pcb != NULL);
LWIP_ASSERT("dhcp_stop: state != NULL", state != NULL);
LWIP_ASSERT("dhcp_stop: state->pcb != NULL", state->pcb != NULL);
if (state != NULL)
{
@@ -966,24 +966,24 @@ static void dhcp_set_state(struct dhcp_state *state, unsigned char new_state)
static void dhcp_option(struct dhcp_state *state, u8_t option_type, u8_t option_len)
{
ASSERT("dhcp_option_short: state->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", state->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_short: state->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", state->options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = option_type;
state->msg_out->options[state->options_out_len++] = option_len;
}
static void dhcp_option_byte(struct dhcp_state *state, u8_t value)
{
ASSERT("dhcp_option_short: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_short: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = value;
}
static void dhcp_option_short(struct dhcp_state *state, u16_t value)
{
ASSERT("dhcp_option_short: state->options_out_len + 2 <= DHCP_OPTIONS_LEN", state->options_out_len + 2 <= DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_short: state->options_out_len + 2 <= DHCP_OPTIONS_LEN", state->options_out_len + 2 <= DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = (value & 0xff00U) >> 8;
state->msg_out->options[state->options_out_len++] = value & 0x00ffU;
}
static void dhcp_option_long(struct dhcp_state *state, u32_t value)
{
ASSERT("dhcp_option_long: state->options_out_len + 4 <= DHCP_OPTIONS_LEN", state->options_out_len + 4 <= DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_long: state->options_out_len + 4 <= DHCP_OPTIONS_LEN", state->options_out_len + 4 <= DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = (value & 0xff000000UL) >> 24;
state->msg_out->options[state->options_out_len++] = (value & 0x00ff0000UL) >> 16;
state->msg_out->options[state->options_out_len++] = (value & 0x0000ff00UL) >> 8;
@@ -1177,8 +1177,8 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
static err_t dhcp_create_request(struct dhcp_state *state)
{
u16_t i;
ASSERT("dhcp_create_request: state->p_out == NULL", state->p_out == NULL);
ASSERT("dhcp_create_request: state->msg_out == NULL", state->msg_out == NULL);
LWIP_ASSERT("dhcp_create_request: state->p_out == NULL", state->p_out == NULL);
LWIP_ASSERT("dhcp_create_request: state->msg_out == NULL", state->msg_out == NULL);
state->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM);
if (state->p_out == NULL)
{
@@ -1213,8 +1213,8 @@ static err_t dhcp_create_request(struct dhcp_state *state)
static void dhcp_delete_request(struct dhcp_state *state)
{
ASSERT("dhcp_free_msg: state->p_out != NULL", state->p_out != NULL);
ASSERT("dhcp_free_msg: state->msg_out != NULL", state->msg_out != NULL);
LWIP_ASSERT("dhcp_free_msg: state->p_out != NULL", state->p_out != NULL);
LWIP_ASSERT("dhcp_free_msg: state->msg_out != NULL", state->msg_out != NULL);
pbuf_free(state->p_out);
state->p_out = NULL;
state->msg_out = NULL;
@@ -1229,14 +1229,14 @@ static void dhcp_delete_request(struct dhcp_state *state)
static void dhcp_option_trailer(struct dhcp_state *state)
{
ASSERT("dhcp_option_trailer: state->msg_out != NULL", state->msg_out != NULL);
ASSERT("dhcp_option_trailer: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_trailer: state->msg_out != NULL", state->msg_out != NULL);
LWIP_ASSERT("dhcp_option_trailer: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = DHCP_OPTION_END;
// packet is still too small, or not 4 byte aligned?
while ((state->options_out_len < DHCP_MIN_OPTIONS_LEN) || (state->options_out_len & 3))
{
//DEBUGF(DHCP_DEBUG, ("dhcp_option_trailer: state->options_out_len=%u, DHCP_OPTIONS_LEN=%u", state->options_out_len, DHCP_OPTIONS_LEN));
ASSERT("dhcp_option_trailer: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
LWIP_ASSERT("dhcp_option_trailer: state->options_out_len < DHCP_OPTIONS_LEN", state->options_out_len < DHCP_OPTIONS_LEN);
state->msg_out->options[state->options_out_len++] = 0;
}
}

View File

@@ -55,7 +55,7 @@ lwip_chksum(void *dataptr, int len)
DEBUGF(INET_DEBUG, ("lwip_chksum(%p, %d)\n", dataptr, len));
for(acc = 0; len > 1; len -= 2) {
// acc = acc + *((u16_t *)dataptr)++;
/* acc = acc + *((u16_t *)dataptr)++;*/
acc += *(u16_t *)dataptr;
dataptr = (void *)((u16_t *)dataptr + 1);
}
@@ -94,9 +94,9 @@ inet_chksum_pseudo(struct pbuf *p,
swapped = 0;
/* iterate through all pbuf in chain */
for(q = p; q != NULL; q = q->next) {
DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", q, 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);
//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) {
acc = (acc & 0xffffUL) + (acc >> 16);
}
@@ -104,7 +104,7 @@ inet_chksum_pseudo(struct pbuf *p,
swapped = 1 - swapped;
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) {

View File

@@ -371,6 +371,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
#if IP_REASSEMBLY
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);
p = ip_reass(p);
if(p == NULL) {
return ERR_OK;
@@ -523,7 +524,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
}
#if IP_FRAG
if (p->tot_len > netif->mtu)
/* don't fragment if interface has mtu set to 0 [loopif] */
if (netif->mtu && (p->tot_len > netif->mtu))
return ip_frag(p,netif,dest);
#endif
@@ -578,20 +580,20 @@ ip_debug_print(struct pbuf *p)
DEBUGF(IP_DEBUG, ("IP header:\n"));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("|%2d |%2d | %2d | %4d | (v, hl, tos, len)\n",
DEBUGF(IP_DEBUG, ("|%2d |%2d | %2u | %4u | (v, hl, tos, len)\n",
IPH_V(iphdr),
IPH_HL(iphdr),
IPH_TOS(iphdr),
ntohs(IPH_LEN(iphdr))));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %5d |%d%d%d| %4d | (id, flags, offset)\n",
DEBUGF(IP_DEBUG, ("| %5u |%u%u%u| %4u | (id, flags, offset)\n",
ntohs(IPH_ID(iphdr)),
ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %2d | %2d | 0x%04x | (ttl, proto, chksum)\n",
DEBUGF(IP_DEBUG, ("| %2u | %2u | 0x%04x | (ttl, proto, chksum)\n",
IPH_TTL(iphdr),
IPH_PROTO(iphdr),
ntohs(IPH_CHKSUM(iphdr))));

View File

@@ -45,6 +45,7 @@
#include "lwip/ip_frag.h"
#include "lwip/netif.h"
#include "lwip/stats.h"
/*
@@ -74,8 +75,8 @@ copy_from_pbuf(struct pbuf *p, u16_t * offset,
}
#define IP_REASS_BUFSIZE 5760
#define IP_REASS_MAXAGE 10
#define IP_REASS_TMO 100
#define IP_REASS_MAXAGE 30
#define IP_REASS_TMO 1000
static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE];
static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8)];
@@ -92,9 +93,11 @@ static u8_t ip_reasstmr;
static void
ip_reass_timer(void *arg)
{
if(ip_reasstmr)
if(ip_reasstmr > 1) {
ip_reasstmr--;
sys_timeout(IP_REASS_TMO, (sys_timeout_handler) ip_reass_timer, NULL);
sys_timeout(IP_REASS_TMO, (sys_timeout_handler) ip_reass_timer, NULL);
} else if(ip_reasstmr == 1)
ip_reasstmr = 0;
}
struct pbuf *
@@ -105,6 +108,10 @@ ip_reass(struct pbuf *p)
u16_t offset, len;
u16_t i;
#ifdef IP_STATS
++lwip_stats.ip_frag.recv;
#endif /* IP_STATS */
iphdr = (struct ip_hdr *) ip_reassbuf;
fraghdr = (struct ip_hdr *) p->payload;
/* If ip_reasstmr is zero, no packet is present in the buffer, so we
@@ -127,6 +134,9 @@ ip_reass(struct pbuf *p)
ip_addr_cmp(&iphdr->dest, &fraghdr->dest) &&
IPH_ID(iphdr) == IPH_ID(fraghdr)) {
DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching old packet\n"));
#ifdef IP_STATS
++lwip_stats.ip_frag.cachehit;
#endif /* IP_STATS */
/* Find out the offset in the reassembly buffer where we should
copy the fragment. */
len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
@@ -138,6 +148,7 @@ ip_reass(struct pbuf *p)
DEBUGF(IP_REASS_DEBUG,
("ip_reass: fragment outside of buffer (%d:%d/%d).\n", offset,
offset + len, IP_REASS_BUFSIZE));
sys_timeout_remove((sys_timeout_handler) ip_reass_timer, NULL);
ip_reasstmr = 0;
goto nullreturn;
}
@@ -225,6 +236,7 @@ ip_reass(struct pbuf *p)
/* If we have come this far, we have a full packet in the
buffer, so we allocate a pbuf and copy the packet into it. We
also reset the timer. */
sys_timeout_remove((sys_timeout_handler) ip_reass_timer, NULL);
ip_reasstmr = 0;
pbuf_free(p);
p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL);
@@ -242,6 +254,13 @@ ip_reass(struct pbuf *p)
q->len > ip_reasslen - i ? ip_reasslen - i : q->len);
i += q->len;
}
#ifdef IP_STATS
++lwip_stats.ip_frag.fw;
#endif /* IP_STATS */
} else {
#ifdef IP_STATS
++lwip_stats.ip_frag.memerr;
#endif /* IP_STATS */
}
DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p));
return p;
@@ -249,6 +268,9 @@ ip_reass(struct pbuf *p)
}
nullreturn:
#ifdef IP_STATS
++lwip_stats.ip_frag.drop;
#endif /* IP_STATS */
pbuf_free(p);
return NULL;
}
@@ -324,6 +346,9 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
pbuf_chain(header, rambuf);
netif->output(netif, header, dest);
#ifdef IP_STATS
++lwip_stats.ip_frag.xmit;
#endif /* IP_STATS */
pbuf_dechain(header);
pbuf_free(header);

View File

@@ -217,7 +217,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
#if IP_DEBUG
/* DEBUGF("ip_input: \n");
ip_debug_print(p);
DEBUGF("ip_input: p->len %d p->tot_len %d\n", p->len, p->tot_len);*/
DEBUGF("ip_input: p->len %u p->tot_len %u\n", p->len, p->tot_len);*/
#endif /* IP_DEBUG */
@@ -237,7 +237,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
/* send ICMP destination protocol unreachable */
icmp_dest_unreach(p, ICMP_DUR_PROTO);
pbuf_free(p);
DEBUGF(IP_DEBUG, ("Unsupported transportation protocol %d\n",
DEBUGF(IP_DEBUG, ("Unsupported transportation protocol %u\n",
iphdr->nexthdr));
#ifdef IP_STATS
@@ -266,7 +266,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
PERF_START;
printf("len %d tot_len %d\n", p->len, p->tot_len);
printf("len %u tot_len %u\n", p->len, p->tot_len);
if(pbuf_header(p, IP_HLEN)) {
DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n"));
#ifdef IP_STATS
@@ -275,7 +275,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
return ERR_BUF;
}
printf("len %d tot_len %d\n", p->len, p->tot_len);
printf("len %u tot_len %u\n", p->len, p->tot_len);
iphdr = p->payload;
@@ -303,7 +303,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
++lwip_stats.ip.xmit;
#endif /* IP_STATS */
DEBUGF(IP_DEBUG, ("ip_output_if: %c%c (len %d)\n", netif->name[0], netif->name[1], p->tot_len));
DEBUGF(IP_DEBUG, ("ip_output_if: %c%c (len %u)\n", netif->name[0], netif->name[1], p->tot_len));
#if IP_DEBUG
ip_debug_print(p);
#endif /* IP_DEBUG */
@@ -350,7 +350,7 @@ ip_debug_print(struct pbuf *p)
iphdr->tclass1, iphdr->tclass2,
iphdr->flow1, iphdr->flow2));
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(IP_DEBUG, ("| %5d | %2d | %2d | (len, nexthdr, hoplim)\n",
DEBUGF(IP_DEBUG, ("| %5u | %2u | %2u | (len, nexthdr, hoplim)\n",
ntohs(iphdr->len),
iphdr->nexthdr,
iphdr->hoplim));

View File

@@ -82,12 +82,12 @@ plug_holes(struct mem *mem)
struct mem *nmem;
struct mem *pmem;
ASSERT("plug_holes: mem >= ram", (u8_t *)mem >= ram);
ASSERT("plug_holes: mem < ram_end", (u8_t *)mem < (u8_t *)ram_end);
ASSERT("plug_holes: mem->used == 0", mem->used == 0);
LWIP_ASSERT("plug_holes: mem >= ram", (u8_t *)mem >= ram);
LWIP_ASSERT("plug_holes: mem < ram_end", (u8_t *)mem < (u8_t *)ram_end);
LWIP_ASSERT("plug_holes: mem->used == 0", mem->used == 0);
/* plug hole forward */
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];
if(mem != nmem && nmem->used == 0 && (u8_t *)nmem != (u8_t *)ram_end) {
@@ -134,6 +134,101 @@ mem_init(void)
#endif /* MEM_STATS */
}
/*-----------------------------------------------------------------------------------*/
void
mem_free(void *rmem)
{
struct mem *mem;
if(rmem == NULL) {
return;
}
sys_sem_wait(mem_sem);
LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end);
if((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
DEBUGF(MEM_DEBUG, ("mem_free: illegal memory\n"));
#ifdef MEM_STATS
++lwip_stats.mem.err;
#endif /* MEM_STATS */
return;
}
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
LWIP_ASSERT("mem_free: mem->used", mem->used);
mem->used = 0;
if(mem < lfree) {
lfree = mem;
}
#ifdef MEM_STATS
lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram) - SIZEOF_STRUCT_MEM;
#endif /* MEM_STATS */
plug_holes(mem);
sys_sem_signal(mem_sem);
}
/*-----------------------------------------------------------------------------------*/
void *
mem_reallocm(void *rmem, mem_size_t newsize)
{
void *nmem;
nmem = mem_malloc(newsize);
if(nmem == NULL) {
return mem_realloc(rmem, newsize);
}
memcpy(nmem, rmem, newsize);
mem_free(rmem);
return nmem;
}
/*-----------------------------------------------------------------------------------*/
void *
mem_realloc(void *rmem, mem_size_t newsize)
{
mem_size_t size;
mem_size_t ptr, ptr2;
struct mem *mem, *mem2;
sys_sem_wait(mem_sem);
LWIP_ASSERT("mem_realloc: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end);
if((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
DEBUGF(MEM_DEBUG, ("mem_realloc: illegal memory\n"));
return rmem;
}
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
ptr = (u8_t *)mem - ram;
size = mem->next - ptr - SIZEOF_STRUCT_MEM;
#ifdef MEM_STATS
lwip_stats.mem.used -= (size - newsize);
#endif /* MEM_STATS */
if(newsize + SIZEOF_STRUCT_MEM + MIN_SIZE < size) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
mem2 = (struct mem *)&ram[ptr2];
mem2->used = 0;
mem2->next = mem->next;
mem2->prev = ptr;
mem->next = ptr2;
if(mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2;
}
plug_holes(mem2);
}
sys_sem_signal(mem_sem);
return rmem;
}
/*-----------------------------------------------------------------------------------*/
void *
mem_malloc(mem_size_t size)
{
@@ -187,12 +282,12 @@ mem_malloc(mem_size_t size)
while(lfree->used && lfree != ram_end) {
lfree = (struct mem *)&ram[lfree->next];
}
ASSERT("mem_malloc: !lfree->used", !lfree->used);
LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used);
}
sys_sem_signal(mem_sem);
ASSERT("mem_malloc: allocated memory not above ram_end.",
LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
(u32_t)mem + SIZEOF_STRUCT_MEM + size <= (u32_t)ram_end);
ASSERT("mem_malloc: allocated memory properly aligned.",
LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
(unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
return (u8_t *)mem + SIZEOF_STRUCT_MEM;
}
@@ -205,98 +300,3 @@ mem_malloc(mem_size_t size)
return NULL;
}
/*-----------------------------------------------------------------------------------*/
void
mem_free(void *rmem)
{
struct mem *mem;
if(rmem == NULL) {
return;
}
sys_sem_wait(mem_sem);
ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end);
if((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
DEBUGF(MEM_DEBUG, ("mem_free: illegal memory\n"));
#ifdef MEM_STATS
++lwip_stats.mem.err;
#endif /* MEM_STATS */
return;
}
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
ASSERT("mem_free: mem->used", mem->used);
mem->used = 0;
if(mem < lfree) {
lfree = mem;
}
#ifdef MEM_STATS
lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram) - SIZEOF_STRUCT_MEM;
#endif /* MEM_STATS */
plug_holes(mem);
sys_sem_signal(mem_sem);
}
/*-----------------------------------------------------------------------------------*/
void *
mem_reallocm(void *rmem, mem_size_t newsize)
{
void *nmem;
nmem = mem_malloc(newsize);
if(nmem == NULL) {
return mem_realloc(rmem, newsize);
}
memcpy(nmem, rmem, newsize);
mem_free(rmem);
return nmem;
}
/*-----------------------------------------------------------------------------------*/
void *
mem_realloc(void *rmem, mem_size_t newsize)
{
mem_size_t size;
mem_size_t ptr, ptr2;
struct mem *mem, *mem2;
sys_sem_wait(mem_sem);
ASSERT("mem_realloc: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end);
if((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
DEBUGF(MEM_DEBUG, ("mem_realloc: illegal memory\n"));
return rmem;
}
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
ptr = (u8_t *)mem - ram;
size = mem->next - ptr - SIZEOF_STRUCT_MEM;
#ifdef MEM_STATS
lwip_stats.mem.used -= (size - newsize);
#endif /* MEM_STATS */
if(newsize + SIZEOF_STRUCT_MEM + MIN_SIZE < size) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
mem2 = (struct mem *)&ram[ptr2];
mem2->used = 0;
mem2->next = mem->next;
mem2->prev = ptr;
mem->next = ptr2;
if(mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2;
}
plug_holes(mem2);
}
sys_sem_signal(mem_sem);
return rmem;
}
/*-----------------------------------------------------------------------------------*/

View File

@@ -179,7 +179,7 @@ memp_malloc(memp_t type)
struct memp *memp;
void *mem;
ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
memp = memp_tab[type];
@@ -192,7 +192,7 @@ memp_malloc(memp_t type)
lwip_stats.memp[type].max = lwip_stats.memp[type].used;
}
#endif /* MEMP_STATS */
ASSERT("memp_malloc: memp properly aligned",
LWIP_ASSERT("memp_malloc: memp properly aligned",
((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);
mem = MEM_ALIGN((u8_t *)memp + sizeof(struct memp));
@@ -245,7 +245,7 @@ memp_free(memp_t type, void *mem)
memp->next = memp_tab[type];
memp_tab[type] = memp;
ASSERT("memp sanity", memp_sanity());
LWIP_ASSERT("memp sanity", memp_sanity());
return;
}

View File

@@ -43,6 +43,7 @@ struct netif *netif_default = NULL;
struct netif *
netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw,
void *state,
void (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif))
{
@@ -55,6 +56,7 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
return NULL;
}
netif->state = state;
netif->num = netifnum++;
netif->input = input;
ip_addr_set(&(netif->ip_addr), ipaddr);
@@ -77,6 +79,36 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
#endif /* NETIF_DEBUG */
return netif;
}
/*-----------------------------------------------------------------------------------*/
void netif_remove(struct netif * netif)
{
if ( netif == NULL ) return;
/* is it the first netif? */
if(netif_list == netif) {
netif_list = netif->next;
}
else
{
/* look for netif further down the list */
struct netif * tmpNetif;
for(tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
if(tmpNetif->next == netif) {
tmpNetif->next = netif->next;
break;
}
}
if(tmpNetif == NULL)
return; /* we didn't find any netif today */
}
if(netif_default == netif)
netif_default = NULL;
DEBUGF(NETIF_DEBUG, ("netif_remove: removed netif"));
mem_free( netif );
}
/*-----------------------------------------------------------------------------------*/
struct netif *
netif_find(char *name)
@@ -131,7 +163,7 @@ netif_set_default(struct netif *netif)
{
netif_default = netif;
DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
netif->name[0], netif->name[1]));
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
}
/*-----------------------------------------------------------------------------------*/
void

View File

@@ -78,11 +78,11 @@ static struct pbuf *pbuf_pool_free_cache = NULL;
void
pbuf_init(void)
{
struct pbuf *p, *q;
struct pbuf *p, *q = 0;
u16_t i;
pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0);
LWIP_ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0);
#ifdef PBUF_STATS
lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
@@ -191,9 +191,6 @@ pbuf_pool_free(struct pbuf *p)
}
#endif /* PBUF_STATS */
#ifdef SYS_LIGHTWEIGHT_PROT
old_level = sys_arch_protect();
#endif /* SYS_LIGHTWEIGHT_PROT */
if(pbuf_pool_alloc_cache == NULL) {
pbuf_pool_alloc_cache = p;
} else {
@@ -244,7 +241,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
case PBUF_RAW:
break;
default:
ASSERT("pbuf_alloc: bad pbuf layer", 0);
LWIP_ASSERT("pbuf_alloc: bad pbuf layer", 0);
return NULL;
}
@@ -292,12 +289,12 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
q->payload = (void *)((u8_t *)q + sizeof(struct pbuf));
r = q;
q->ref = 1;
q = q->next;
/*q = q->next; DJH: Appears to be an unnecessary statement*/
rsize -= PBUF_POOL_BUFSIZE;
}
r->next = NULL;
ASSERT("pbuf_alloc: pbuf->payload properly aligned",
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
((u32_t)p->payload % MEM_ALIGNMENT) == 0);
break;
case PBUF_RAM:
@@ -312,7 +309,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
p->next = NULL;
p->flags = PBUF_FLAG_RAM;
ASSERT("pbuf_alloc: pbuf->payload properly aligned",
LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
((u32_t)p->payload % MEM_ALIGNMENT) == 0);
break;
case PBUF_ROM:
@@ -328,7 +325,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
p->flags = PBUF_FLAG_ROM;
break;
default:
ASSERT("pbuf_alloc: erroneous flag", 0);
LWIP_ASSERT("pbuf_alloc: erroneous flag", 0);
return NULL;
}
p->ref = 1;
@@ -426,7 +423,7 @@ pbuf_realloc(struct pbuf *p, u16_t size)
struct pbuf *q, *r;
u16_t rsize;
ASSERT("pbuf_realloc: sane p->flags", p->flags == PBUF_FLAG_POOL ||
LWIP_ASSERT("pbuf_realloc: sane p->flags", p->flags == PBUF_FLAG_POOL ||
p->flags == PBUF_FLAG_ROM ||
p->flags == PBUF_FLAG_RAM);
@@ -549,11 +546,11 @@ pbuf_free(struct pbuf *p)
PERF_START;
ASSERT("pbuf_free: sane flags", p->flags == PBUF_FLAG_POOL ||
LWIP_ASSERT("pbuf_free: sane flags", p->flags == PBUF_FLAG_POOL ||
p->flags == PBUF_FLAG_ROM ||
p->flags == PBUF_FLAG_RAM);
ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
#ifdef SYS_LIGHTWEIGHT_PROT
/* Since decrementing ref cannot be guarranteed to be a single machine operation
@@ -564,7 +561,7 @@ pbuf_free(struct pbuf *p)
/* Decrement reference count. */
p->ref--;
q = NULL;
/*q = NULL; DJH: Unnecessary statement*/
/* If reference count == 0, actually deallocate pbuf. */
if(p->ref == 0) {
#ifdef SYS_LIGHTWEIGHT_PROT

View File

@@ -38,6 +38,14 @@
#include "lwip/memp.h"
#if (NO_SYS == 0)
struct sswt_cb
{
int timeflag;
sys_sem_t *psem;
};
/*-----------------------------------------------------------------------------------*/
void
sys_mbox_fetch(sys_mbox_t mbox, void **msg)
@@ -52,7 +60,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
again:
timeouts = sys_arch_timeouts();
if(timeouts->next == NULL) {
if(!timeouts || !timeouts->next) {
sys_arch_mbox_fetch(mbox, msg, 0);
} else {
if(timeouts->next->time > 0) {
@@ -70,7 +78,10 @@ sys_mbox_fetch(sys_mbox_t mbox, void **msg)
h = tmptimeout->h;
arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
h(arg);
if(h != NULL) {
DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
h(arg);
}
/* We try again to fetch a message from the mbox. */
goto again;
@@ -104,7 +115,7 @@ sys_sem_wait(sys_sem_t sem)
timeouts = sys_arch_timeouts();
if(timeouts->next == NULL) {
if(!timeouts || !timeouts->next) {
sys_arch_sem_wait(sem, 0);
} else {
if(timeouts->next->time > 0) {
@@ -122,7 +133,10 @@ sys_sem_wait(sys_sem_t sem)
h = tmptimeout->h;
arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
h(arg);
if(h != NULL) {
DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg));
h(arg);
}
/* We try again to fetch a message from the mbox. */
@@ -158,6 +172,9 @@ sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
timeouts = sys_arch_timeouts();
DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%u h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg));
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
if(timeouts->next == NULL) {
timeouts->next = timeout;
return;
@@ -183,5 +200,86 @@ sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
}
}
/* Go through timeout list (for this task only) and remove the first matching entry,
even though the timeout has not triggered yet.
*/
/*-----------------------------------------------------------------------------------*/
void
sys_timeout_remove(sys_timeout_handler h, void *arg)
{
struct sys_timeouts *timeouts;
struct sys_timeout *prev_t, *t;
timeouts = sys_arch_timeouts();
if (timeouts->next == NULL)
return;
for (t = timeouts->next, prev_t = NULL; t != NULL; prev_t = t, t = t->next)
{
if ((t->h == h) && (t->arg == arg))
{
/* We have a match */
/* Unlink from previous in list */
if (prev_t == NULL)
timeouts->next = t->next;
else
prev_t->next = t->next;
/* If not the last one, add time of this one back to next */
if (t->next != NULL)
t->next->time += t->time;
memp_free(MEMP_SYS_TIMEOUT, t);
return;
}
}
return;
}
/*-----------------------------------------------------------------------------------*/
static void
sswt_handler(void *arg)
{
struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;
/* Timeout. Set flag to TRUE and signal semephore */
sswt_cb->timeflag = 1;
sys_sem_signal(*(sswt_cb->psem));
}
/* Wait for a semaphore with timeout (specified in ms) */
/* timeout = 0: wait forever */
/* Returns 0 on timeout. 1 otherwise */
/*-----------------------------------------------------------------------------------*/
int
sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
{
struct sswt_cb sswt_cb;
sswt_cb.psem = &sem;
sswt_cb.timeflag = 0;
/* If timeout is zero, then just wait forever */
if (timeout > 0)
/* Create a timer and pass it the address of our flag */
sys_timeout(timeout, sswt_handler, &sswt_cb);
sys_sem_wait(sem);
/* Was it a timeout? */
if (sswt_cb.timeflag)
{
/* timeout */
return 0;
} else {
/* Not a timeout. Remove timeout entry */
sys_timeout_remove(sswt_handler, &sswt_cb);
return 1;
}
}
/*-----------------------------------------------------------------------------------*/
#endif /* NO_SYS */

View File

@@ -69,6 +69,8 @@ struct tcp_pcb *tcp_tmp_pcb;
static u8_t tcp_timer;
static u16_t tcp_new_port(void);
/*-----------------------------------------------------------------------------------*/
/*
* tcp_init():
@@ -250,6 +252,10 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{
struct tcp_pcb *cpcb;
if(port == 0) {
port = tcp_new_port();
}
/* Check if the address already is in use. */
for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs;
cpcb != NULL; cpcb = cpcb->next) {
@@ -275,7 +281,7 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
pcb->local_ip = *ipaddr;
}
pcb->local_port = port;
DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %d\n", port));
DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %u\n", port));
return ERR_OK;
}
#if LWIP_CALLBACK_API
@@ -337,7 +343,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
!(pcb->flags & TF_ACK_NOW)) {
tcp_ack(pcb);
}
DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %d bytes, wnd %u (%u).\n",
DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %u bytes, wnd %u (%u).\n",
len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd));
}
/*-----------------------------------------------------------------------------------*/
@@ -352,11 +358,15 @@ static u16_t
tcp_new_port(void)
{
struct tcp_pcb *pcb;
static u16_t port = 4096;
#ifndef TCP_LOCAL_PORT_RANGE_START
#define TCP_LOCAL_PORT_RANGE_START 4096
#define TCP_LOCAL_PORT_RANGE_END 0x7fff
#endif
static u16_t port = TCP_LOCAL_PORT_RANGE_START;
again:
if(++port > 0x7fff) {
port = 4096;
if(++port > TCP_LOCAL_PORT_RANGE_END) {
port = TCP_LOCAL_PORT_RANGE_START;
}
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
@@ -393,7 +403,7 @@ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
err_t ret;
u32_t iss;
DEBUGF(TCP_DEBUG, ("tcp_connect to port %d\n", port));
DEBUGF(TCP_DEBUG, ("tcp_connect to port %u\n", port));
if(ipaddr != NULL) {
pcb->remote_ip = *ipaddr;
} else {
@@ -458,9 +468,9 @@ tcp_slowtmr(void)
if (pcb == NULL) DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs"));
while(pcb != NULL) {
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb"));
ASSERT("tcp_slowtmr: active pcb->state != CLOSED", pcb->state != CLOSED);
ASSERT("tcp_slowtmr: active pcb->state != LISTEN", pcb->state != LISTEN);
ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN", pcb->state != LISTEN);
LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
pcb_remove = 0;
@@ -476,7 +486,7 @@ tcp_slowtmr(void)
if(pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
/* Time for a retransmission. */
DEBUGF(TCP_RTO_DEBUG, ("tcp_slowtmr: rtime %d pcb->rto %d\n",
DEBUGF(TCP_RTO_DEBUG, ("tcp_slowtmr: rtime %u pcb->rto %u\n",
pcb->rtime, pcb->rto));
/* Double retransmission time-out unless we are trying to
@@ -537,11 +547,11 @@ tcp_slowtmr(void)
tcp_pcb_purge(pcb);
/* Remove PCB from tcp_active_pcbs list. */
if(prev != NULL) {
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;
} else {
/* This PCB was the first. */
ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
tcp_active_pcbs = pcb->next;
}
@@ -573,7 +583,7 @@ tcp_slowtmr(void)
prev = NULL;
pcb = tcp_tw_pcbs;
while(pcb != NULL) {
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;
/* Check if this PCB has stayed long enough in TIME-WAIT */
@@ -588,11 +598,11 @@ tcp_slowtmr(void)
tcp_pcb_purge(pcb);
/* Remove PCB from tcp_tw_pcbs list. */
if(prev != NULL) {
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;
} else {
/* This PCB was the first. */
ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);
LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);
tcp_tw_pcbs = pcb->next;
}
pcb2 = pcb->next;
@@ -1002,7 +1012,7 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
}
pcb->state = CLOSED;
ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane());
LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane());
}
/*-----------------------------------------------------------------------------------*/
/*
@@ -1036,7 +1046,8 @@ tcp_debug_print(struct tcp_hdr *tcphdr)
DEBUGF(TCP_DEBUG, ("| %08lu | (ack no)\n",
tcphdr->ackno));
DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(TCP_DEBUG, ("| %2d | |%d%d%d%d%d| %5d | (offset, flags (",
DEBUGF(TCP_DEBUG, ("| %2u | |%u%u%u%u%u| %5u | (offset, flags (",
TCPH_OFFSET(tcphdr),
TCPH_FLAGS(tcphdr) >> 4 & 1,
TCPH_FLAGS(tcphdr) >> 4 & 1,
TCPH_FLAGS(tcphdr) >> 3 & 1,
@@ -1047,7 +1058,7 @@ tcp_debug_print(struct tcp_hdr *tcphdr)
tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
DEBUGF(TCP_DEBUG, ("), win)\n"));
DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(TCP_DEBUG, ("| 0x%04x | %5d | (chksum, urgp)\n",
DEBUGF(TCP_DEBUG, ("| 0x%04x | %5u | (chksum, urgp)\n",
ntohs(tcphdr->chksum), ntohs(tcphdr->urgp)));
DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
}
@@ -1122,21 +1133,21 @@ tcp_debug_print_pcbs(void)
struct tcp_pcb *pcb;
DEBUGF(TCP_DEBUG, ("Active PCB states:\n"));
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
DEBUGF(TCP_DEBUG, ("Local port %d, foreign port %d snd_nxt %lu rcv_nxt %lu ",
DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) {
DEBUGF(TCP_DEBUG, ("Local port %d, foreign port %d snd_nxt %lu rcv_nxt %lu ",
DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n"));
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
DEBUGF(TCP_DEBUG, ("Local port %d, foreign port %d snd_nxt %lu rcv_nxt %lu ",
DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
@@ -1148,12 +1159,12 @@ tcp_pcbs_sane(void)
{
struct tcp_pcb *pcb;
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
ASSERT("tcp_pcbs_sane: active pcb->state != CLOSED", pcb->state != CLOSED);
ASSERT("tcp_pcbs_sane: active pcb->state != LISTEN", pcb->state != LISTEN);
ASSERT("tcp_pcbs_sane: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != LISTEN", pcb->state != LISTEN);
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
}
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
ASSERT("tcp_pcbs_sane: tw pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
LWIP_ASSERT("tcp_pcbs_sane: tw pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
}
return 1;
}

View File

@@ -157,9 +157,9 @@ tcp_input(struct pbuf *p, struct netif *inp)
for an active connection. */
prev = NULL;
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
ASSERT("tcp_input: active pcb->state != CLOSED", pcb->state != CLOSED);
ASSERT("tcp_input: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN);
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 != LISTEN", pcb->state != LISTEN);
if(pcb->remote_port == tcphdr->src &&
pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
@@ -168,13 +168,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* Move this PCB to the front of the list so that subsequent
lookups will be faster (we exploit locality in TCP segment
arrivals). */
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) {
prev->next = pcb->next;
pcb->next = tcp_active_pcbs;
tcp_active_pcbs = pcb;
}
ASSERT("tcp_input: pcb->next != pcb (after cache)", pcb->next != pcb);
LWIP_ASSERT("tcp_input: pcb->next != pcb (after cache)", pcb->next != pcb);
break;
}
prev = pcb;
@@ -185,7 +185,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
in the TIME-WAIT state. */
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
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 &&
pcb->local_port == tcphdr->dest &&
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)) &&
@@ -201,7 +201,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
}
/* Finally, if we still did not get a match, we check all PCBs that
are LISTENing for incomming connections. */
are LISTENing for incoming connections. */
prev = NULL;
for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if((ip_addr_isany(&(lpcb->local_ip)) ||
@@ -326,7 +326,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
pbuf_free(p);
}
ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());
LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane());
PERF_STOP("tcp_input");
}
/*-----------------------------------------------------------------------------------*/
@@ -450,7 +450,7 @@ tcp_process(struct tcp_pcb *pcb)
if(acceptable) {
DEBUGF(TCP_INPUT_DEBUG, ("tcp_process: Connection RESET\n"));
ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_input: pcb->state != CLOSED", pcb->state != CLOSED);
recv_flags = TF_RESET;
pcb->flags &= ~TF_ACK_DELAY;
return ERR_RST;
@@ -500,7 +500,7 @@ tcp_process(struct tcp_pcb *pcb)
TCP_SEQ_LEQ(ackno, pcb->snd_nxt)) {
pcb->state = ESTABLISHED;
DEBUGF(DEMO_DEBUG, ("TCP connection established %d -> %d.\n", inseg.tcphdr->src, inseg.tcphdr->dest));
ASSERT("pcb->accept != NULL", pcb->accept != NULL);
LWIP_ASSERT("pcb->accept != NULL", pcb->accept != NULL);
/* Call the accept function. */
TCP_EVENT_ACCEPT(pcb, ERR_OK, err);
if(err != ERR_OK) {
@@ -727,7 +727,7 @@ tcp_receive(struct tcp_pcb *pcb)
DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unacked)\n", pcb->snd_queuelen));
#ifdef LWIP_DEBUG
if(pcb->snd_queuelen != 0) {
ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL);
}
#endif /* LWIP_DEBUG */
@@ -758,7 +758,7 @@ tcp_receive(struct tcp_pcb *pcb)
DEBUGF(TCP_QLEN_DEBUG, ("%d (after freeing unsent)\n", pcb->snd_queuelen));
#ifdef LWIP_DEBUG
if(pcb->snd_queuelen != 0) {
ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL);
}
#endif /* LWIP_DEBUG */

View File

@@ -129,7 +129,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
#ifdef LWIP_DEBUG
if(pcb->snd_queuelen != 0) {
ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL);
}
#endif /* LWIP_DEBUG */
@@ -310,7 +310,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
DEBUGF(TCP_QLEN_DEBUG, ("tcp_enqueue: %d (after enqueued)\n", pcb->snd_queuelen));
#ifdef LWIP_DEBUG
if(pcb->snd_queuelen != 0) {
ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL);
}
@@ -333,7 +333,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
}
#ifdef LWIP_DEBUG
if(pcb->snd_queuelen != 0) {
ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
LWIP_ASSERT("tcp_enqueue: valid queue length", pcb->unacked != NULL ||
pcb->unsent != NULL);
}

View File

@@ -28,7 +28,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: udp.c,v 1.16 2003/01/30 15:02:48 likewise Exp $
* $Id: udp.c,v 1.17 2003/02/06 22:18:56 davidhaas Exp $
*/
/*-----------------------------------------------------------------------------------*/
@@ -93,6 +93,7 @@ udp_lookup(struct ip_hdr *iphdr, struct netif *inp)
u16_t src, dest;
PERF_START;
(void)inp;
udphdr = (struct udp_hdr *)(u8_t *)iphdr + IPH_HL(iphdr) * 4;
@@ -177,7 +178,7 @@ udp_input(struct pbuf *p, struct netif *inp)
udphdr = (struct udp_hdr *)((u8_t *)p->payload - UDP_HLEN);
DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %d\n", p->tot_len));
DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %u\n", p->tot_len));
src = NTOHS(udphdr->src);
dest = NTOHS(udphdr->dest);
@@ -341,7 +342,14 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
err_t err;
struct pbuf *hdr;
DEBUGF(UDP_DEBUG, ("udp_send"));
DEBUGF(UDP_DEBUG, ("udp_send\n"));
if(pcb->local_port == 0) {
err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
if(err != ERR_OK)
return err;
}
/* hdr will point to the UDP header pbuf if an extra header pbuf has
to be allocated. */
hdr = NULL;
@@ -359,7 +367,7 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
/* have p point to header pbuf */
p = hdr;
}
DEBUGF(UDP_DEBUG, ("udp_send: got pbuf"));
DEBUGF(UDP_DEBUG, ("udp_send: got pbuf\n"));
udphdr = p->payload;
udphdr->src = htons(pcb->local_port);
@@ -382,11 +390,11 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
src_ip = &(pcb->local_ip);
}
DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %d\n", p->tot_len));
DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %u\n", p->tot_len));
/* UDP Lite protocol? */
if(pcb->flags & UDP_FLAGS_UDPLITE) {
DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %u", p->tot_len));
DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE packet length %u\n", p->tot_len));
/* set UDP message length in UDP header */
udphdr->len = htons(pcb->chksum_len);
/* calculate checksum */
@@ -400,7 +408,7 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
snmp_inc_udpoutdatagrams();
#endif
} else {
DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %u", p->tot_len));
DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %u\n", p->tot_len));
udphdr->len = htons(p->tot_len);
/* calculate checksum */
if((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
@@ -408,11 +416,11 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
/* chksum zero must become 0xffff, as zero means 'no checksum' */
if(udphdr->chksum == 0x0000) udphdr->chksum = 0xffff;
}
DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum %x", udphdr->chksum));
DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum %x\n", udphdr->chksum));
#if LWIP_SNMP > 0
snmp_inc_udpoutdatagrams();
#endif
DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if(,,,,IP_PROTO_UDP,)"));
DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if(,,,,IP_PROTO_UDP,)\n"));
/* output to IP */
err = ip_output_if(p, src_ip, &pcb->remote_ip, UDP_TTL, IP_PROTO_UDP, netif);
}
@@ -466,6 +474,23 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
}
/* bind local address */
ip_addr_set(&pcb->local_ip, ipaddr);
if(port == 0) {
#ifndef UDP_LOCAL_PORT_RANGE_START
#define UDP_LOCAL_PORT_RANGE_START 4096
#define UDP_LOCAL_PORT_RANGE_END 0x7fff
#endif
port = UDP_LOCAL_PORT_RANGE_START;
ipcb = udp_pcbs;
while((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
if(ipcb->local_port == port) {
port++;
ipcb = udp_pcbs;
} else
ipcb = ipcb->next;
}
if(ipcb) /* no more ports available in local range */
return ERR_USE;
}
pcb->local_port = port;
/* We need to place the PCB on the list if not already there. */
@@ -474,7 +499,7 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
udp_pcbs = pcb;
}
DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %d\n", port));
DEBUGF(UDP_DEBUG, ("udp_bind: bound to port %u\n", port));
return ERR_OK;
}
/**
@@ -492,10 +517,34 @@ err_t
udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{
struct udp_pcb *ipcb;
if(pcb->local_port == 0) {
err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
if(err != ERR_OK)
return err;
}
ip_addr_set(&pcb->remote_ip, ipaddr);
pcb->remote_port = port;
pcb->flags |= UDP_FLAGS_CONNECTED;
/* Nail down local IP for netconn_addr()/getsockname() */
if(ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
struct netif *netif;
if((netif = ip_route(&(pcb->remote_ip))) == NULL) {
DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
#ifdef UDP_STATS
++lwip_stats.udp.rterr;
#endif /* UDP_STATS */
return ERR_RTE;
}
pcb->local_ip = netif->ip_addr;
} else if(ip_addr_isany(&pcb->remote_ip)) {
pcb->local_ip.addr = 0;
}
/* Insert UDP PCB into the list of active UDP PCBs. */
for(ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
if(pcb == ipcb) {
@@ -577,10 +626,10 @@ udp_debug_print(struct udp_hdr *udphdr)
{
DEBUGF(UDP_DEBUG, ("UDP header:\n"));
DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(UDP_DEBUG, ("| %5d | %5d | (src port, dest port)\n",
DEBUGF(UDP_DEBUG, ("| %5u | %5u | (src port, dest port)\n",
ntohs(udphdr->src), ntohs(udphdr->dest)));
DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
DEBUGF(UDP_DEBUG, ("| %5d | 0x%04x | (len, chksum)\n",
DEBUGF(UDP_DEBUG, ("| %5u | 0x%04x | (len, chksum)\n",
ntohs(udphdr->len), ntohs(udphdr->chksum)));
DEBUGF(UDP_DEBUG, ("+-------------------------------+\n"));
return 0;